diff --git a/core/01_core.js b/core/01_core.js index fda3e49773..e5e2c9fd5d 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -161,9 +161,14 @@ function opAsync(opName, ...args) { const promiseId = nextPromiseId++; let p = setPromise(promiseId); - const maybeError = ops[opName](promiseId, ...args); - // Handle sync error (e.g: error parsing args) - if (maybeError) return unwrapOpResult(maybeError); + try { + ops[opName](promiseId, ...args); + } catch (err) { + // Cleanup the just-created promise + getPromise(promiseId); + // Rethrow the error + throw err; + } p = PromisePrototypeThen(p, unwrapOpResult); if (opCallTracingEnabled) { // Capture a stack trace by creating a new `Error` object. We remove the