From 702074c3182bea1a51363f816e2977124e292ed1 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 10 Jan 2025 17:27:37 +0900 Subject: [PATCH] feat: support options in error constructors --- core/01_core.js | 12 ++++++------ testing/unit/error_test.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/core/01_core.js b/core/01_core.js index 17db6e53a..71d94741c 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -301,24 +301,24 @@ // errors in the JS code (eg. "deno_net") so they are provided in "Deno.core" // but later reexported on "Deno.errors" class BadResource extends Error { - constructor(msg) { - super(msg); + constructor(msg, options) { + super(msg, options); this.name = "BadResource"; } } const BadResourcePrototype = BadResource.prototype; class Interrupted extends Error { - constructor(msg) { - super(msg); + constructor(msg, options) { + super(msg, options); this.name = "Interrupted"; } } const InterruptedPrototype = Interrupted.prototype; class NotCapable extends Error { - constructor(msg) { - super(msg); + constructor(msg, options) { + super(msg, options); this.name = "NotCapable"; } } diff --git a/testing/unit/error_test.ts b/testing/unit/error_test.ts index 53d77d2be..aefb3d303 100644 --- a/testing/unit/error_test.ts +++ b/testing/unit/error_test.ts @@ -10,3 +10,18 @@ test(function testCustomError() { assert(e instanceof Deno.core.BadResource); } }); + +test(function testJsErrorConstructors() { + const error = new Error("message"); + const badResource = new Deno.core.BadResource("bad resource", { cause: error }); + assertEquals(badResource.message, "bad resource"); + assertEquals(badResource.cause, error); + + const Interrupted = new Deno.core.Interrupted("interrupted", { cause: error }); + assertEquals(Interrupted.message, "interrupted"); + assertEquals(Interrupted.cause, error); + + const notCapable = new Deno.core.NotCapable("not capable", { cause: error }); + assertEquals(notCapable.message, "not capable"); + assertEquals(notCapable.cause, error); +}) \ No newline at end of file