2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2023-01-14 23:18:58 -05:00
|
|
|
use std::fmt::Display;
|
|
|
|
use std::fmt::{self};
|
2021-10-19 18:00:45 -04:00
|
|
|
|
2023-01-14 23:18:58 -05:00
|
|
|
use serde::de;
|
|
|
|
use serde::ser;
|
2021-10-19 18:00:45 -04:00
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
2022-09-19 04:25:03 -04:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
2022-07-28 06:46:10 -04:00
|
|
|
#[non_exhaustive]
|
2021-10-19 18:00:45 -04:00
|
|
|
pub enum Error {
|
|
|
|
Message(String),
|
|
|
|
|
|
|
|
ExpectedBoolean,
|
|
|
|
ExpectedInteger,
|
2022-04-12 08:36:21 -04:00
|
|
|
ExpectedNumber,
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedString,
|
|
|
|
ExpectedArray,
|
|
|
|
ExpectedMap,
|
|
|
|
ExpectedEnum,
|
|
|
|
ExpectedObject,
|
2022-01-20 09:11:09 -05:00
|
|
|
ExpectedBuffer,
|
2022-04-02 07:35:57 -04:00
|
|
|
ExpectedDetachable,
|
2023-02-22 12:32:38 -05:00
|
|
|
ExpectedExternal,
|
2021-10-19 18:00:45 -04:00
|
|
|
|
|
|
|
ExpectedUtf8,
|
2022-03-07 05:12:36 -05:00
|
|
|
ExpectedLatin1,
|
2021-10-19 18:00:45 -04:00
|
|
|
|
|
|
|
LengthMismatch,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ser::Error for Error {
|
|
|
|
fn custom<T: Display>(msg: T) -> Self {
|
|
|
|
Error::Message(msg.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl de::Error for Error {
|
|
|
|
fn custom<T: Display>(msg: T) -> Self {
|
|
|
|
Error::Message(msg.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Error::Message(msg) => formatter.write_str(msg),
|
2023-01-27 10:43:16 -05:00
|
|
|
err => formatter.write_str(format!("serde_v8 error: {err:?}").as_ref()),
|
2021-10-19 18:00:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for Error {}
|