Skip to content
← All rules
API ContractsAPI contracts

api-contracts/no-ambiguous-failure-contracts

Directly exported functions should not mix nullable or sentinel results with thrown errors unless each failure representation has a visibly distinct role.

failuresexportsreturn-values
TypeScript
export function findUser(id: string) { if (!id) throw new Error("missing"); return db.find(id) ?? null; }
Finding

Disallow overlapping public failure channels.

Setup

Install the package, register its plugin factory, then enable the rule.

Install the package

pnpm add -D @scruple/api-contracts

Register the plugin

In scruple.config.ts, register the factory under the api-contracts namespace used by the rule ID.

import { apiContracts } from "@scruple/api-contracts";

plugins: {
  "api-contracts": apiContracts(),
},

Enable the rule

"api-contracts/no-ambiguous-failure-contracts": "warn"
Package
@scruple/api-contracts
Default threshold
0.8
Minimum confidence
0.7

Released under the MIT License.