summaryrefslogtreecommitdiff
path: root/core/error.rs
diff options
context:
space:
mode:
authorJan Špaček <patek.mail@gmail.com>2022-10-26 17:30:44 +0200
committerGitHub <noreply@github.com>2022-10-26 17:30:44 +0200
commit642118fdeb06817636fe03d0d8428fbd7927094d (patch)
tree9b74dc6d4267dc97818c21470af36311bfee9ac2 /core/error.rs
parenta57faa8a0a1bbe895859146b1baee1b991e7ad99 (diff)
fix(core) Include causes when converting anyhow errors to JS exceptions (#16397)
When an op returns an `anyhow` error with a cause (usually added using the `.context()` method), the `Error` thrown into JavaScript contains only the message of the outernmost error in the chain. This PR simply changes the formatting of `anyhow::Error` from `"{}"` to `"{:#}"`: This significantly improves errors for code that embeds Deno and defines custom ops. For example, in [chiselstrike/chiselstrike](https://github.com/chiselstrike/chiselstrike), this PR improves an error message like ``` Error: could not plan migration ``` to ``` Error: could not plan migration: could not migrate table for entity "E": could not add column for field "title": the field does not have a default value ```
Diffstat (limited to 'core/error.rs')
-rw-r--r--core/error.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/error.rs b/core/error.rs
index 5ee3355c4..9ad99c6da 100644
--- a/core/error.rs
+++ b/core/error.rs
@@ -105,7 +105,7 @@ pub fn to_v8_error<'a>(
let cb = cb.open(scope);
let this = v8::undefined(scope).into();
let class = v8::String::new(scope, get_class(error)).unwrap();
- let message = v8::String::new(scope, &error.to_string()).unwrap();
+ let message = v8::String::new(scope, &format!("{:#}", error)).unwrap();
let mut args = vec![class.into(), message.into()];
if let Some(code) = crate::error_codes::get_error_code(error) {
args.push(v8::String::new(scope, code).unwrap().into());