A literal is thrown or used to reject a promise, so it carries no stack trace
What it finds
throw "not found", Promise.reject(404), reject({ code: 1 }): a value that is not an Error carries no stack trace, so whoever catches it cannot tell where it came from, and code that reads error.message gets undefined.
Reported are literals other than regular expressions, templates, and array and object literals that are thrown, given to Promise.reject, or given to the second parameter of a new Promise executor. Rejections without a value are left alone.
From the rule's source, reject_with_non_error.rs.
function find(id: string) { if (id === "") { throw "empty id";tx0 reports: this throws a value that is not an Error } if (id === "x") { return Promise.reject({ code: 404 });tx0 reports: this rejects a promise with a value that is not an Error } return new Promise((resolve, reject) => { if (id === "y") { reject(`missing ${id}`);tx0 reports: this rejects a promise with a value that is not an Error } reject(new Error("missing")); resolve(id); });}function fail(message: string) { throw new Error(message);} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:reject-with-non-error" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:reject-with-non-error] reason="..."tx0 explain tx0/ts:reject-with-non-error shows the same in the terminal. Found a false positive? Report it.