Skip to content

Commit 1d2aee5

Browse files
Update blog/2024-12-05-boa-release-020/index.mdx
Co-authored-by: raskad <[email protected]>
1 parent f8440e1 commit 1d2aee5

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

blog/2024-12-05-boa-release-020/index.mdx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,13 @@ Embedders can now create native errors in Rust and pass them into the JavaScript
6060
The below example creates a new `JsError` from a Rust standard error [`err`](https://doc.rust-lang.org/std/error/trait.Error.html). This will create a new `JsNativeError` with the message of the standard error.
6161

6262
````rust
63-
/// # Examples
64-
///
65-
/// ```
66-
/// # use boa_engine::JsError;
67-
/// let error = std::io::Error::new(std::io::ErrorKind::Other, "oh no!");
68-
/// let js_error: JsError = JsError::from_rust(error);
69-
///
70-
/// assert_eq!(js_error.as_native().unwrap().message(), "oh no!");
71-
/// assert!(js_error.as_native().unwrap().cause().is_none());
72-
/// ```
73-
#[must_use]
74-
pub fn from_rust(err: impl error::Error) -> Self {
75-
let mut native_err = JsNativeError::error().with_message(err.to_string());
76-
if let Some(source) = err.source() {
77-
native_err = native_err.with_cause(Self::from_rust(source));
78-
}
79-
80-
Self::from_native(native_err)
81-
}
82-
````
63+
use boa_engine::JsError;
64+
65+
let error = std::io::Error::new(std::io::ErrorKind::Other, "oh no!");
66+
let js_error: JsError = JsError::from_rust(error);
67+
68+
assert_eq!(js_error.as_native().unwrap().message(), "oh no!");
69+
assert!(js_error.as_native().unwrap().cause().is_none());
8370

8471
## Boa Runtime
8572

0 commit comments

Comments
 (0)