# No `throw new Error("not implemented")` in production code

- **Pattern:** `ab-000267` (`ai-slop-half-finished.incomplete-impl.throw-not-implemented`)
- **Severity:** medium
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-000267
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-000267)

## Why it matters

A `throw new Error('not implemented')` turns into an HTTP 500 the first time any caller hits that code path. Because AI generates these as scaffolding — `calculateRefund`, `sendInvoice`, `getUserBalance` — the thrown paths often sit directly on revenue-critical flows. Users encounter them during checkout, refund, or billing and abandon the transaction; the defect then masquerades as a generic 500 in observability and takes hours to trace back to the stub.

## Severity rationale

Medium because the failure is loud but only triggers when the specific path executes, often on a less-travelled flow.

## Remediation

Implement the function against real logic or remove it and adjust every caller. Do not leave scaffold throws behind; a `// TODO` next to a thrown error is still a 500 in production. Fix at `src/lib/billing.ts`:

```ts
export function calculateRefund(amount: number) {
  const feePercent = 0.03
  return amount * (1 - feePercent)
}
```

## Detection

- **ID:** `throw-not-implemented`
- **Severity:** `medium`
- **What to look for:** Walk all non-test source files. Count all `throw` statements whose error message matches this regex (case-insensitive): `\b(not\s*implemented|not\s*yet\s*implemented|todo|implement\s*me|coming\s*soon|placeholder|stub|fixme|unimplemented|notimpl)\b`. Also count `throw new NotImplementedError()` regardless of message. Also count `throw 'not implemented'` and similar string throws. EXCLUDE abstract class method bodies (files containing `abstract class`) AND interface stubs.
- **Pass criteria:** 0 `throw` statements with "not implemented" messages in production code. Report: "Scanned X source files, 0 'not implemented' throws."
- **Fail criteria:** At least 1 source file contains a `throw` with a "not implemented" style message.
- **Skip (N/A) when:** Project has 0 source files.
- **Detail on fail:** `"2 'not implemented' throws: throw new Error('Not yet implemented') in src/lib/billing.ts line 34 (function 'calculateRefund'), throw new Error('TODO: implement') in src/lib/email.ts line 12"`
- **Remediation:** A `throw new Error("not implemented")` means any code path that reaches this line will 500. AI often generates these as "scaffolding for later" — but the AI never comes back to replace them. Either implement the function or remove it and fix the caller:

  ```ts
  // Bad: function stub that throws
  export function calculateRefund(amount: number) {
    throw new Error('Not yet implemented')
  }

  // Good: implement it
  export function calculateRefund(amount: number) {
    const feePercent = 0.03
    return amount * (1 - feePercent)
  }
  ```

Taxons: placeholder-hygiene

HTML version: https://auditbuffet.com/patterns/ab-000267
