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 OutOfRange,
12 Internal(String),
14 BigIntOverflow,
16 UnexpectedType,
18 #[doc(hidden)]
19 __NonExhaustive,
20}
21
22impl From<std::convert::Infallible> for ValueError {
25 fn from(_: std::convert::Infallible) -> Self {
26 unreachable!()
27 }
28}
29
30impl fmt::Display for ValueError {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 use ValueError::*;
33 match self {
34 InvalidString(e) => write!(
35 f,
36 "Value conversion failed - invalid non-utf8 string: {}",
37 e
38 ),
39 StringWithZeroBytes(_) => write!(f, "String contains \\0 bytes",),
40 OutOfRange => write!(f, "Value conversion failed - out of range"),
41 Internal(e) => write!(f, "Value conversion failed - internal error: {}", e),
42 BigIntOverflow => write!(f, "BigInt overflow"),
43 UnexpectedType => write!(f, "Could not convert - received unexpected type"),
44 __NonExhaustive => unreachable!(),
45 }
46 }
47}
48
49impl error::Error for ValueError {}