pub struct Failure { /* private fields */ }Expand description
An error recorded on a span: what exporters report about it.
It carries what exporters print: the error’s type (class), message,
code, where it was raised, its stack trace and the error that caused it.
Failure::new records the caller’s location; Failure::from_error
converts any std::error::Error with its chain of sources.
PHP: the \Throwable passed to setError() or finish(); class is
$e::class, previous is getPrevious().
use utopia_span::Failure;
let root = Failure::new("LogicException", "root cause");
let error = Failure::new("RuntimeException", "outer").code(42).previous(root);
assert_eq!(error.class(), "RuntimeException");
assert_eq!(error.code_value(), 42);
assert_eq!(error.cause().map(|c| c.message()), Some("root cause"));$root = new \LogicException('root cause');
$error = new \RuntimeException('outer', 42, $root);
echo $error::class, "\n"; // RuntimeException
echo $error->getCode(), "\n"; // 42
echo $error->getPrevious()->getMessage(), "\n"; // root causeImplementations§
Source§impl Failure
impl Failure
Sourcepub fn new(class: impl Into<String>, message: impl Into<Vec<u8>>) -> Self
pub fn new(class: impl Into<String>, message: impl Into<Vec<u8>>) -> Self
A failure of type class with message, raised where this is called,
with code 0, no trace and no cause.
PHP: new $class($message).
Sourcepub fn from_error<E: Error + ?Sized>(error: &E) -> Self
pub fn from_error<E: Error + ?Sized>(error: &E) -> Self
A failure describing error: its type name, message and chain of
sources (each source becomes the Failure::cause of the one before,
with the type std::error::Error).
use utopia_span::Failure;
let error = "x".parse::<i32>().unwrap_err();
let failure = Failure::from_error(&error);
assert_eq!(failure.class(), "core::num::error::ParseIntError");
assert_eq!(failure.message(), "invalid digit found in string");Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
The message, when it is UTF-8 (the empty string otherwise; see
Failure::message_bytes).
PHP: getMessage().
Sourcepub fn message_bytes(&self) -> &[u8] ⓘ
pub fn message_bytes(&self) -> &[u8] ⓘ
The message, as bytes.
Sourcepub fn code_value(&self) -> i64
pub fn code_value(&self) -> i64
The error code.
PHP: getCode().
Trait Implementations§
impl Eq for Failure
Source§impl Error for Failure
impl Error for Failure
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
impl StructuralPartialEq for Failure
Auto Trait Implementations§
impl Forget for Failure
impl Freeze for Failure
impl Move for Failure
impl RefUnwindSafe for Failure
impl Send for Failure
impl Sync for Failure
impl Unpin for Failure
impl UnsafeUnpin for Failure
impl UnwindSafe for Failure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.