/** * @fileoverview Require oRPC handlers to throw a failed `ServiceResult` as a declared error. * * In a handler passed to `implement(...).handler()`, a failure branch is the body of * `if (isFailure(result))`, `if (!isSuccess(result))` or `if (!result.isSuccess)`, or the `else` of * `if (isSuccess(result))`, `if (result.isSuccess)` or `if (!isFailure(result))`. Every `throw` in * it must throw `toDeclaredError({ errors, error })` or one of the handler's own `errors` * constructors, so the response keeps the status and body the contract declares. A failure branch * may still `return`, for a handler that answers a failure with a success response. * * The rule is syntactic. It recognizes `implement` from `@orpc/nest` or `@orpc/server`, `isFailure` * and `isSuccess` from `@clipboard-health/util-ts`, and `toDeclaredError` from * `@clipboard-health/api-nestjs` by their named imports. The `result.isSuccess` form matches any * object's `isSuccess` property. Out of scope: * - throws outside a failure branch, such as a `catch` block's or one after an early * `if (isSuccess(result)) return`; * - compound conditions, such as `isFailure(a) || isFailure(b)`; * - throws inside a function defined in the branch, such as a callback's; * - a handler reached through a variable, such as `const os = implement(contract)`. */ import type { Rule } from "@oxlint/plugins"; declare const rule: Rule; export default rule;