2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2023-01-14 20:18:58 -08:00
|
|
|
use std::fmt::Display;
|
|
|
|
use std::fmt::{self};
|
2021-10-20 00:00:45 +02:00
|
|
|
|
2023-01-14 20:18:58 -08:00
|
|
|
use serde::de;
|
|
|
|
use serde::ser;
|
2021-10-20 00:00:45 +02:00
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
2022-09-19 10:25:03 +02:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
2022-07-28 12:46:10 +02:00
|
|
|
#[non_exhaustive]
|
2021-10-20 00:00:45 +02:00
|
|
|
pub enum Error {
|
|
|
|
Message(String),
|
|
|
|
|
|
|
|
ExpectedBoolean,
|
|
|
|
ExpectedInteger,
|
2022-04-12 14:36:21 +02:00
|
|
|
ExpectedNumber,
|
2021-10-20 00:00:45 +02:00
|
|
|
ExpectedString,
|
|
|
|
ExpectedArray,
|
|
|
|
ExpectedMap,
|
|
|
|
ExpectedEnum,
|
|
|
|
ExpectedObject,
|
2022-01-20 15:11:09 +01:00
|
|
|
ExpectedBuffer,
|
2022-04-02 13:35:57 +02:00
|
|
|
ExpectedDetachable,
|
2021-10-20 00:00:45 +02:00
|
|
|
|
|
|
|
ExpectedUtf8,
|
2022-03-07 11:12:36 +01:00
|
|
|
ExpectedLatin1,
|
2021-10-20 00:00:45 +02: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-20 00:00:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for Error {}
|