diff --git a/serialize-error/deno.json b/serialize-error/deno.json new file mode 100644 index 0000000..8172823 --- /dev/null +++ b/serialize-error/deno.json @@ -0,0 +1,5 @@ +{ + "imports": { + "serialize-error": "npm:serialize-error@^12.0.0" + } +} diff --git a/serialize-error/deno.lock b/serialize-error/deno.lock new file mode 100644 index 0000000..832a01b --- /dev/null +++ b/serialize-error/deno.lock @@ -0,0 +1,32 @@ +{ + "version": "4", + "specifiers": { + "npm:@types/node@*": "22.5.4", + "npm:serialize-error@*": "12.0.0" + }, + "npm": { + "@types/node@22.5.4": { + "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", + "dependencies": [ + "undici-types" + ] + }, + "serialize-error@12.0.0": { + "integrity": "sha512-ZYkZLAvKTKQXWuh5XpBw7CdbSzagarX39WyZ2H07CDLC5/KfsRGlIXV8d4+tfqX1M7916mRqR1QfNHSij+c9Pw==", + "dependencies": [ + "type-fest" + ] + }, + "type-fest@4.33.0": { + "integrity": "sha512-s6zVrxuyKbbAsSAD5ZPTB77q4YIdRctkTbJ2/Dqlinwz+8ooH2gd+YA7VA6Pa93KML9GockVvoxjZ2vHP+mu8g==" + }, + "undici-types@6.19.8": { + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" + } + }, + "workspace": { + "dependencies": [ + "npm:serialize-error@12" + ] + } +} diff --git a/serialize-error/main.ts b/serialize-error/main.ts new file mode 100644 index 0000000..cbff747 --- /dev/null +++ b/serialize-error/main.ts @@ -0,0 +1,7 @@ +import { addKnownErrorConstructor } from "npm:serialize-error"; + +export class E extends Error { + code = "ERR"; +} + +addKnownErrorConstructor(E); diff --git a/serialize-error/test.ts b/serialize-error/test.ts new file mode 100644 index 0000000..fe96b1b --- /dev/null +++ b/serialize-error/test.ts @@ -0,0 +1,13 @@ +import assert from "node:assert"; +import { deserializeError, serializeError } from "npm:serialize-error"; +import { E } from "./main.ts"; + +Deno.test("serializeError", () => { + const e = serializeError(new E()); + assert(e.code === "ERR"); + assert(e.stack?.match(/^Error\n/)); +}); + +Deno.test("deserializeError", () => { + assert(deserializeError({ name: "E", message: "🦄" }) instanceof E); +});