Skip to content

ddd-ts-kit/domain-no-generic-error

Architecture id: domain/no-generic-error (added by this plugin). Default severity: error in recommended, error in strict.

Applies to: domain/ and application/ of a context, tests excluded.

An expected business failure has a name and a stable code that presentation maps to a status in one place. new Error("...") gives the caller a sentence to parse.

  • throw new Error(...) and throw Error(...)

Incorrect:

throw new Error('Invoice already issued');

Correct:

throw new InvoiceAlreadyIssued(this.id);

None.

rules."domain/no-generic-error" in ddd-ts-kit.config.json set to off silences the rule, and // ddd-ts-kit-disable-next-line domain/no-generic-error -- <reason> silences one line, exactly as for ddd-ts-kit check.

  • Only the global Error is reported: TypeError and friends are left to review.
  • A generic error returned in a Result (err(new Error())) or rejected (Promise.reject) is not seen.

New with this plugin: the CLI checker has no equivalent, because the shape of a class needs a syntax tree.