diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-11-04 16:44:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-04 16:44:34 +0100 |
commit | 44511e4f330e2d7099a16ed836629fa73dde9831 (patch) | |
tree | 7be25493513d50314ab71452693b317ef4194a49 /core/01_core.js | |
parent | efe956b4fd51818e3a982b9d7c4111c408d07291 (diff) |
feat(runtime): give OS errors .code attributes (#12591)
This adds `.code` attributes to errors returned by the op-layer, facilitating classifying OS errors and helping node-compat.
Similar to Node, these `.code` attributes are stringified names of unix ERRNOs, the mapping tables are generated by [tools/codegen_error_codes.js](https://gist.github.com/AaronO/dfa1106cc6c7e2a6ebe4dba9d5248858) and derived from libuv and rust's std internals
Diffstat (limited to 'core/01_core.js')
-rw-r--r-- | core/01_core.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/core/01_core.js b/core/01_core.js index 24b844453..9d4bab65d 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -119,6 +119,10 @@ const err = errorBuilder ? errorBuilder(res.message) : new Error( `Unregistered error class: "${className}"\n ${res.message}\n Classes of errors returned from ops should be registered via Deno.core.registerErrorClass().`, ); + // Set .code if error was a known OS error, see error_codes.rs + if (res.code) { + err.code = res.code; + } // Strip unwrapOpResult() and errorBuilder() calls from stack trace ErrorCaptureStackTrace(err, unwrapOpResult); throw err; |