quickjs_rusty/errors/
value_error.rs1use std::{error, fmt};
2
3#[derive(PartialEq, Eq, Debug)]
5pub enum ValueError {
6 InvalidString(std::str::Utf8Error),
8 StringWithZeroBytes(std::ffi::NulError),
10 Internal(String),
12 BigIntOverflow,
14 UnexpectedType,
16 #[doc(hidden)]
17 __NonExhaustive,
18}
19
20impl From<std::convert::Infallible> for ValueError {
23 fn from(_: std::convert::Infallible) -> Self {
24 unreachable!()
25 }
26}
27
28impl fmt::Display for ValueError {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 use ValueError::*;
31 match self {
32 InvalidString(e) => write!(
33 f,
34 "Value conversion failed - invalid non-utf8 string: {}",
35 e
36 ),
37 StringWithZeroBytes(_) => write!(f, "String contains \\0 bytes",),
38 Internal(e) => write!(f, "Value conversion failed - internal error: {}", e),
39 BigIntOverflow => write!(f, "BigInt overflow"),
40 UnexpectedType => write!(f, "Could not convert - received unexpected type"),
41 __NonExhaustive => unreachable!(),
42 }
43 }
44}
45
46impl error::Error for ValueError {}