From 865a2fc9520b7c53387a7c83e2fb170fefd5b94b Mon Sep 17 00:00:00 2001 From: Iris Artin Date: Tue, 30 Nov 2021 23:52:35 -0500 Subject: [PATCH 1/2] Propagate original error in RuntimeError.cause (#1) --- src/errors.js | 3 ++- src/variable.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/errors.js b/src/errors.js index b6597e88..fb8582e5 100644 --- a/src/errors.js +++ b/src/errors.js @@ -1,6 +1,7 @@ -export function RuntimeError(message, input) { +export function RuntimeError(message, input, cause = undefined) { this.message = message + ""; this.input = input; + this.cause = cause; } RuntimeError.prototype = Object.create(Error.prototype); diff --git a/src/variable.js b/src/variable.js index 00132d81..671bce75 100644 --- a/src/variable.js +++ b/src/variable.js @@ -58,7 +58,7 @@ function variable_undefined() { function variable_rejector(variable) { return function(error) { if (error === variable_undefined) throw new RuntimeError(variable._name + " is not defined", variable._name); - if (error instanceof Error && error.message) throw new RuntimeError(error.message, variable._name); + if (error instanceof Error && error.message) throw new RuntimeError(error.message, variable._name, error); throw new RuntimeError(variable._name + " could not be resolved", variable._name); }; } From c7eb7f7af081075890b9f90b969d172d1eb91ae8 Mon Sep 17 00:00:00 2001 From: Iris Artin Date: Wed, 1 Dec 2021 01:35:56 -0500 Subject: [PATCH 2/2] Update src/errors.js Co-authored-by: Mike Bostock --- src/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors.js b/src/errors.js index fb8582e5..279ff81d 100644 --- a/src/errors.js +++ b/src/errors.js @@ -1,4 +1,4 @@ -export function RuntimeError(message, input, cause = undefined) { +export function RuntimeError(message, input, cause) { this.message = message + ""; this.input = input; this.cause = cause;