pub struct JsNativeError { pub kind:JsNativeErrorKind,/* private fields */}Expand description
Native representation of an idealError object from Javascript.
This representation is more space efficient than itsJsObject equivalent,since it doesn’t need to create a whole newJsObject to be instantiated.Prefer using this overJsError when you don’t need to throwplainJsValues as errors, or when you need to inspect the error typeof aJsError.
§Examples
letnative_error = JsNativeError::uri().with_message("cannot decode uri");matchnative_error.kind { JsNativeErrorKind::Uri => {/* handle URI error*/}_=>unreachable!(),}assert_eq!(native_error.message(),"cannot decode uri");Fields§
§kind:JsNativeErrorKindThe kind of native error (e.g.TypeError,SyntaxError, etc.)
Implementations§
Source§implJsNativeError
implJsNativeError
Sourcepub constNO_INSTRUCTIONS_REMAIN: Self
pub constNO_INSTRUCTIONS_REMAIN: Self
DefaultNoInstructionsRemain kindJsNativeError.
Sourcepub constRUNTIME_LIMIT: Self
pub constRUNTIME_LIMIT: Self
Defaulterror kindJsNativeError.
Sourcepub const fnaggregate(errors:Vec<JsError>) -> Self
pub const fnaggregate(errors:Vec<JsError>) -> Self
Creates a newJsNativeError of kindAggregateError from a list ofJsErrors, withemptymessage and undefinedcause.
§Examples
letinner_errors =vec![ JsNativeError::typ().into(), JsNativeError::syntax().into()];leterror = JsNativeError::aggregate(inner_errors);assert!(matches!( error.kind, JsNativeErrorKind::Aggregate(referrors)iferrors.len() ==2));Sourcepub const fnis_aggregate(&self) ->bool
pub const fnis_aggregate(&self) ->bool
Check if it’s aJsNativeErrorKind::Aggregate.
Sourcepub const fnerror() -> Self
pub const fnerror() -> Self
Creates a newJsNativeError of kindError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::error();assert!(matches!(error.kind, JsNativeErrorKind::Error));Sourcepub const fnis_error(&self) ->bool
pub const fnis_error(&self) ->bool
Check if it’s aJsNativeErrorKind::Error.
Sourcepub const fneval() -> Self
pub const fneval() -> Self
Creates a newJsNativeError of kindEvalError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::eval();assert!(matches!(error.kind, JsNativeErrorKind::Eval));Sourcepub const fnis_eval(&self) ->bool
pub const fnis_eval(&self) ->bool
Check if it’s aJsNativeErrorKind::Eval.
Sourcepub const fnrange() -> Self
pub const fnrange() -> Self
Creates a newJsNativeError of kindRangeError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::range();assert!(matches!(error.kind, JsNativeErrorKind::Range));Sourcepub const fnis_range(&self) ->bool
pub const fnis_range(&self) ->bool
Check if it’s aJsNativeErrorKind::Range.
Sourcepub const fnreference() -> Self
pub const fnreference() -> Self
Creates a newJsNativeError of kindReferenceError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::reference();assert!(matches!(error.kind, JsNativeErrorKind::Reference));Sourcepub const fnis_reference(&self) ->bool
pub const fnis_reference(&self) ->bool
Check if it’s aJsNativeErrorKind::Reference.
Sourcepub const fnsyntax() -> Self
pub const fnsyntax() -> Self
Creates a newJsNativeError of kindSyntaxError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::syntax();assert!(matches!(error.kind, JsNativeErrorKind::Syntax));Sourcepub const fnis_syntax(&self) ->bool
pub const fnis_syntax(&self) ->bool
Check if it’s aJsNativeErrorKind::Syntax.
Sourcepub const fntyp() -> Self
pub const fntyp() -> Self
Creates a newJsNativeError of kindTypeError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::typ();assert!(matches!(error.kind, JsNativeErrorKind::Type));Sourcepub const fnis_type(&self) ->bool
pub const fnis_type(&self) ->bool
Check if it’s aJsNativeErrorKind::Type.
Sourcepub const fnuri() -> Self
pub const fnuri() -> Self
Creates a newJsNativeError of kindUriError, with emptymessage and undefinedcause.
§Examples
leterror = JsNativeError::uri();assert!(matches!(error.kind, JsNativeErrorKind::Uri));Sourcepub const fnis_uri(&self) ->bool
pub const fnis_uri(&self) ->bool
Check if it’s aJsNativeErrorKind::Uri.
Sourcepub const fnno_instructions_remain() -> Self
pub const fnno_instructions_remain() -> Self
Creates a newJsNativeError that indicates that the context hit its execution limit. Thisis only used in a fuzzing context.
Sourcepub const fnis_no_instructions_remain(&self) ->bool
pub const fnis_no_instructions_remain(&self) ->bool
Check if it’s aJsNativeErrorKind::NoInstructionsRemain.
Sourcepub const fnruntime_limit() -> Self
pub const fnruntime_limit() -> Self
Creates a newJsNativeError that indicates that the context exceeded the runtime limits.
Sourcepub const fnis_runtime_limit(&self) ->bool
pub const fnis_runtime_limit(&self) ->bool
Check if it’s aJsNativeErrorKind::RuntimeLimit.
Sourcepub fnwith_message<S>(self, message: S) -> Self
pub fnwith_message<S>(self, message: S) -> Self
Sets the message of this error.
§Examples
leterror = JsNativeError::range().with_message("number too large");assert_eq!(error.message(),"number too large");Sourcepub fnwith_cause<V>(self, cause: V) -> Self
pub fnwith_cause<V>(self, cause: V) -> Self
Sets the cause of this error.
§Examples
letcause = JsNativeError::syntax();leterror = JsNativeError::error().with_cause(cause);assert!(error.cause().unwrap().as_native().is_some());Sourcepub fnmessage(&self) -> &str
pub fnmessage(&self) -> &str
Gets themessage of this error.
This is equivalent to theNativeError.prototype.messageproperty.
§Examples
leterror = JsNativeError::range().with_message("number too large");assert_eq!(error.message(),"number too large");Sourcepub fncause(&self) ->Option<&JsError>
pub fncause(&self) ->Option<&JsError>
Gets thecause of this error.
This is equivalent to theNativeError.prototype.causeproperty.
§Examples
letcause = JsNativeError::syntax();leterror = JsNativeError::error().with_cause(cause);assert!(error.cause().unwrap().as_native().is_some());Sourcepub fnto_opaque(&self, context: &mutContext) ->JsObject
pub fnto_opaque(&self, context: &mutContext) ->JsObject
Converts this native error to its opaque representation as aJsObject.
§Examples
letcontext =&mutContext::default();leterror = JsNativeError::error().with_message("error!");leterror_obj = error.to_opaque(context);assert!(error_obj.is::<Error>());assert_eq!( error_obj.get(js_string!("message"), context).unwrap(),js_string!("error!").into())§Panics
If converting aJsNativeErrorKind::RuntimeLimit to an opaque object.
Trait Implementations§
Source§implClone forJsNativeError
implClone forJsNativeError
Source§fnclone(&self) ->JsNativeError
fnclone(&self) ->JsNativeError
1.0.0 ·Source§fnclone_from(&mut self, source: &Self)
fnclone_from(&mut self, source: &Self)
source.Read moreSource§implDebug forJsNativeError
implDebug forJsNativeError
Source§implDisplay forJsNativeError
implDisplay forJsNativeError
Source§implError forJsNativeError
implError forJsNativeError
Source§fnsource(&self) ->Option<&(dynError + 'static)>
fnsource(&self) ->Option<&(dynError + 'static)>
1.0.0 ·Source§fndescription(&self) -> &str
fndescription(&self) -> &str
Source§implFrom<Error> forJsNativeError
implFrom<Error> forJsNativeError
Source§implFrom<IcuError> forJsNativeError
implFrom<IcuError> forJsNativeError
Source§implFrom<JsNativeError> forJsError
implFrom<JsNativeError> forJsError
Source§fnfrom(error:JsNativeError) -> Self
fnfrom(error:JsNativeError) -> Self
Source§implFrom<TemporalError> forJsNativeError
implFrom<TemporalError> forJsNativeError
Source§fnfrom(value:TemporalError) -> Self
fnfrom(value:TemporalError) -> Self
Source§implPartialEq forJsNativeError
implPartialEq forJsNativeError
Source§implTrace forJsNativeError
implTrace forJsNativeError
Source§unsafe fntrace_non_roots(&self)
unsafe fntrace_non_roots(&self)
Source§fnrun_finalizer(&self)
fnrun_finalizer(&self)
Finalize::finalize on this object and allcontained subobjects.implEq forJsNativeError
implStructuralPartialEq forJsNativeError
Auto Trait Implementations§
implFreeze forJsNativeError
impl !RefUnwindSafe forJsNativeError
impl !Send forJsNativeError
impl !Sync forJsNativeError
implUnpin forJsNativeError
impl !UnwindSafe forJsNativeError
Blanket Implementations§
Source§impl<T>BorrowMut<T> for Twhere T: ?Sized,
impl<T>BorrowMut<T> for Twhere T: ?Sized,
Source§fnborrow_mut(&mut self) ->&mut T
fnborrow_mut(&mut self) ->&mut T
Source§impl<T>CloneToUninit for Twhere T:Clone,
impl<T>CloneToUninit for Twhere T:Clone,
Source§impl<Q, K>Equivalent<K> for Q
impl<Q, K>Equivalent<K> for Q
Source§fnequivalent(&self, key:&K) ->bool
fnequivalent(&self, key:&K) ->bool
key and returntrue if they are equal.Source§impl<Q, K>Equivalent<K> for Q
impl<Q, K>Equivalent<K> for Q
Source§impl<T>IntoEither for T
impl<T>IntoEither for T
Source§fninto_either(self, into_left:bool) ->Either<Self, Self>
fninto_either(self, into_left:bool) ->Either<Self, Self>
self into aLeft variant ofEither<Self, Self>ifinto_left istrue.Convertsself into aRight variant ofEither<Self, Self>otherwise.Read moreSource§fninto_either_with<F>(self, into_left: F) ->Either<Self, Self>
fninto_either_with<F>(self, into_left: F) ->Either<Self, Self>
self into aLeft variant ofEither<Self, Self>ifinto_left(&self) returnstrue.Convertsself into aRight variant ofEither<Self, Self>otherwise.Read moreSource§impl<T>Pipe for Twhere T: ?Sized,
impl<T>Pipe for Twhere T: ?Sized,
Source§fnpipe<R>(self, func: implFnOnce(Self) -> R) -> Rwhere Self:Sized,
fnpipe<R>(self, func: implFnOnce(Self) -> R) -> Rwhere Self:Sized,
Source§fnpipe_ref<'a, R>(&'a self, func: implFnOnce(&'a Self) -> R) -> Rwhere R: 'a,
fnpipe_ref<'a, R>(&'a self, func: implFnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function.Read moreSource§fnpipe_ref_mut<'a, R>(&'a mut self, func: implFnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
fnpipe_ref_mut<'a, R>(&'a mut self, func: implFnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function.Read moreSource§fnpipe_borrow<'a, B, R>(&'a self, func: implFnOnce(&'a B) -> R) -> R
fnpipe_borrow<'a, B, R>(&'a self, func: implFnOnce(&'a B) -> R) -> R
Source§fnpipe_borrow_mut<'a, B, R>( &'a mut self, func: implFnOnce(&'a mut B) -> R,) -> R
fnpipe_borrow_mut<'a, B, R>( &'a mut self, func: implFnOnce(&'a mut B) -> R,) -> R
Source§fnpipe_as_ref<'a, U, R>(&'a self, func: implFnOnce(&'a U) -> R) -> R
fnpipe_as_ref<'a, U, R>(&'a self, func: implFnOnce(&'a U) -> R) -> R
self, then passesself.as_ref() into the pipe function.Source§fnpipe_as_mut<'a, U, R>(&'a mut self, func: implFnOnce(&'a mut U) -> R) -> R
fnpipe_as_mut<'a, U, R>(&'a mut self, func: implFnOnce(&'a mut U) -> R) -> R
self, then passesself.as_mut() into the pipefunction.Source§fnpipe_deref<'a, T, R>(&'a self, func: implFnOnce(&'a T) -> R) -> R
fnpipe_deref<'a, T, R>(&'a self, func: implFnOnce(&'a T) -> R) -> R
self, then passesself.deref() into the pipe function.Source§impl<T>Tap for T
impl<T>Tap for T
Source§fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
fntap_borrow<B>(self, func: implFnOnce(&B)) -> Self
Borrow<B> of a value.Read moreSource§fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
fntap_borrow_mut<B>(self, func: implFnOnce(&mut B)) -> Self
BorrowMut<B> of a value.Read moreSource§fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
fntap_ref<R>(self, func: implFnOnce(&R)) -> Self
AsRef<R> view of a value.Read moreSource§fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
fntap_ref_mut<R>(self, func: implFnOnce(&mut R)) -> Self
AsMut<R> view of a value.Read moreSource§fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
fntap_deref<T>(self, func: implFnOnce(&T)) -> Self
Deref::Target of a value.Read moreSource§fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
fntap_deref_mut<T>(self, func: implFnOnce(&mut T)) -> Self
Deref::Target of a value.Read moreSource§fntap_dbg(self, func: implFnOnce(&Self)) -> Self
fntap_dbg(self, func: implFnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self
fntap_mut_dbg(self, func: implFnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in releasebuilds.Source§fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
fntap_borrow_dbg<B>(self, func: implFnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in releasebuilds.Source§fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
fntap_borrow_mut_dbg<B>(self, func: implFnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in releasebuilds.Source§fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
fntap_ref_dbg<R>(self, func: implFnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in releasebuilds.Source§fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
fntap_ref_mut_dbg<R>(self, func: implFnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in releasebuilds.Source§fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
fntap_deref_dbg<T>(self, func: implFnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in releasebuilds.