From 44511e4f330e2d7099a16ed836629fa73dde9831 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 4 Nov 2021 16:44:34 +0100 Subject: 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 --- core/ops.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/ops.rs') diff --git a/core/ops.rs b/core/ops.rs index ab233ef29..f62fe7a8e 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -140,6 +140,7 @@ pub struct OpError { #[serde(rename = "$err_class_name")] class_name: &'static str, message: String, + code: Option<&'static str>, } pub fn serialize_op_result( @@ -151,6 +152,7 @@ pub fn serialize_op_result( Err(err) => OpResult::Err(OpError { class_name: (state.borrow().get_error_class_fn)(&err), message: err.to_string(), + code: crate::error_codes::get_error_code(&err), }), } } -- cgit v1.2.3