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;
|
2021-10-19 18:00:45 -04:00
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
2023-04-12 20:03:56 -04:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
|
2022-07-28 06:46:10 -04:00
|
|
|
#[non_exhaustive]
|
2021-10-19 18:00:45 -04:00
|
|
|
pub enum Error {
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("{0}")]
|
2021-10-19 18:00:45 -04:00
|
|
|
Message(String),
|
|
|
|
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: boolean")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedBoolean,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: integer")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedInteger,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: number")]
|
2022-04-12 08:36:21 -04:00
|
|
|
ExpectedNumber,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: string")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedString,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: array")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedArray,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: map")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedMap,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: enum")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedEnum,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: object")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedObject,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: buffer")]
|
2022-01-20 09:11:09 -05:00
|
|
|
ExpectedBuffer,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: detachable")]
|
2022-04-02 07:35:57 -04:00
|
|
|
ExpectedDetachable,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: external")]
|
2023-02-22 12:32:38 -05:00
|
|
|
ExpectedExternal,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: bigint")]
|
2023-03-16 12:59:47 -04:00
|
|
|
ExpectedBigInt,
|
2021-10-19 18:00:45 -04:00
|
|
|
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: utf8")]
|
2021-10-19 18:00:45 -04:00
|
|
|
ExpectedUtf8,
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: invalid type, expected: latin1")]
|
2022-03-07 05:12:36 -05:00
|
|
|
ExpectedLatin1,
|
2021-10-19 18:00:45 -04:00
|
|
|
|
2023-04-12 20:03:56 -04:00
|
|
|
#[error("serde_v8 error: unsupported type")]
|
2023-03-22 00:13:24 -04:00
|
|
|
UnsupportedType,
|
2023-04-12 20:03:56 -04:00
|
|
|
|
|
|
|
#[error("serde_v8 error: length mismatch, got: {0}, expected: {1}")]
|
|
|
|
LengthMismatch(usize, usize),
|
2021-10-19 18:00:45 -04:00
|
|
|
}
|
|
|
|
|
2023-04-12 20:03:56 -04:00
|
|
|
impl serde::ser::Error for Error {
|
2021-10-19 18:00:45 -04:00
|
|
|
fn custom<T: Display>(msg: T) -> Self {
|
|
|
|
Error::Message(msg.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-12 20:03:56 -04:00
|
|
|
impl serde::de::Error for Error {
|
2021-10-19 18:00:45 -04:00
|
|
|
fn custom<T: Display>(msg: T) -> Self {
|
|
|
|
Error::Message(msg.to_string())
|
|
|
|
}
|
|
|
|
}
|