quickjs_rusty/errors/
value_error.rsuse std::{error, fmt};
#[derive(PartialEq, Eq, Debug)]
pub enum ValueError {
InvalidString(std::str::Utf8Error),
StringWithZeroBytes(std::ffi::NulError),
Internal(String),
BigIntOverflow,
UnexpectedType,
#[doc(hidden)]
__NonExhaustive,
}
impl From<std::convert::Infallible> for ValueError {
fn from(_: std::convert::Infallible) -> Self {
unreachable!()
}
}
impl fmt::Display for ValueError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ValueError::*;
match self {
InvalidString(e) => write!(
f,
"Value conversion failed - invalid non-utf8 string: {}",
e
),
StringWithZeroBytes(_) => write!(f, "String contains \\0 bytes",),
Internal(e) => write!(f, "Value conversion failed - internal error: {}", e),
BigIntOverflow => write!(f, "BigInt overflow"),
UnexpectedType => write!(f, "Could not convert - received unexpected type"),
__NonExhaustive => unreachable!(),
}
}
}
impl error::Error for ValueError {}