Skip to content

throwErrors

Reports throwing values that are not Error objects.

✅ This rule is included in the ts logical presets.

Only Error objects (or objects that extend Error) should be thrown. Throwing non-Error values has several downsides:

  • No stack trace information for debugging
  • Inconsistent error handling behavior
  • Cannot use standard error properties like cause, message, or name

This rule reports on any throw statement where the value being thrown is not an Error.

throw "Something went wrong";
throw { message: "error", code: 500 };

This rule is not configurable.

If you’re working with legacy code that throws non-Error values and refactoring would be too costly, you may disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.