This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- move JasonError to the api::wasm - get rid of HandlerDetachedError
- Loading branch information
1 parent
e580a72
commit 1ff5d5f
Showing
23 changed files
with
732 additions
and
512 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,81 @@ | ||
//! App error exported to JS side. | ||
use derive_more::From; | ||
use std::fmt::{Debug, Display}; | ||
|
||
use derive_more::{Display, From}; | ||
use tracerr::{Trace, Traced}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::utils; | ||
use crate::{platform, utils::JsCaused}; | ||
|
||
/// Representation of an app error exported to JS side. | ||
/// | ||
/// Contains JS side error if it's the cause, and a trace information. | ||
#[wasm_bindgen] | ||
#[derive(From)] | ||
pub struct JasonError(utils::JasonError); | ||
#[derive(From, Clone, Debug, Display)] | ||
#[display(fmt = "{}: {}\n{}", name, message, trace)] | ||
pub struct JasonError { | ||
/// Name of this [`JasonError`]. | ||
name: &'static str, | ||
|
||
/// Message describing this [`JasonError`]. | ||
message: String, | ||
|
||
/// [`Trace`] information of this [`JasonError`]. | ||
trace: Trace, | ||
|
||
/// Optional cause of this [`JasonError`] as a JS side error. | ||
source: Option<platform::Error>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl JasonError { | ||
/// Returns a name of this error. | ||
#[must_use] | ||
pub fn name(&self) -> String { | ||
self.0.name() | ||
self.name.to_owned() | ||
} | ||
|
||
/// Returns a message of this errors. | ||
/// Returns a message of this error. | ||
#[must_use] | ||
pub fn message(&self) -> String { | ||
self.0.message() | ||
self.message.clone() | ||
} | ||
|
||
/// Returns a trace information of this error. | ||
#[must_use] | ||
pub fn trace(&self) -> String { | ||
self.0.trace() | ||
self.trace.to_string() | ||
} | ||
|
||
/// Returns a JS side error if it's the cause. | ||
#[must_use] | ||
pub fn source(&self) -> Option<js_sys::Error> { | ||
self.0.source().and_then(|a| a.sys_cause) | ||
self.source.clone().and_then(|e| e.sys_cause) | ||
} | ||
} | ||
|
||
impl<E: JsCaused + Display> From<(E, Trace)> for JasonError | ||
where | ||
E::Error: Into<platform::Error>, | ||
{ | ||
#[inline] | ||
fn from((err, trace): (E, Trace)) -> Self { | ||
Self { | ||
name: err.name(), | ||
message: err.to_string(), | ||
trace, | ||
source: err.js_cause().map(Into::into), | ||
} | ||
} | ||
} | ||
|
||
impl<E: JsCaused + Display> From<Traced<E>> for JasonError | ||
where | ||
E::Error: Into<platform::Error>, | ||
{ | ||
#[inline] | ||
fn from(traced: Traced<E>) -> Self { | ||
Self::from(traced.into_parts()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.