Files
scriptc/tests/corpus/6813-node-island-handle-errors/lib.cjs
T
Malte UblandClaude Opus 5.5 a1b6fda11c Run npm packages in Node islands: object handles and compiler routing (NI-4)
Node islands stack, part 2 of 11 (scriptc-perf/results/islands-prs/PLAN.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:49:52 -07:00

31 lines
881 B
JavaScript

"use strict";
class NotFound extends Error {
constructor(what) {
super(`${what} not found`);
this.name = "NotFound";
this.code = "E_NOT_FOUND";
}
}
let last;
exports.NotFound = NotFound;
exports.fail = (kind) => {
if (kind === "type") {
const e = new TypeError("bad type");
e.code = "ERR_BAD";
last = e;
throw e;
}
if (kind === "range") throw (last = new RangeError("out of range"));
if (kind === "custom") throw (last = new NotFound("thing"));
if (kind === "string") throw "just a string";
if (kind === "object") throw (last = { reason: "plain object" });
return "no throw";
};
exports.isLast = (e) => e === last;
exports.inspectError = (e) =>
`${e instanceof Error} ${e.constructor.name} ${e.name} ${JSON.stringify(e.message)} ${e.code} ${typeof e.stack}`;
exports.rethrow = (e) => {
throw e;
};
exports.call = (o, m) => o[m]();