summaryrefslogtreecommitdiff
path: root/serde_v8/error.rs
blob: 94ac3c0a54afda6ac7366fabdbbc7a65a6508133 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use std::fmt::Display;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
  #[error("{0}")]
  Message(String),

  #[error("serde_v8 error: invalid type, expected: boolean")]
  ExpectedBoolean,
  #[error("serde_v8 error: invalid type, expected: integer")]
  ExpectedInteger,
  #[error("serde_v8 error: invalid type, expected: number")]
  ExpectedNumber,
  #[error("serde_v8 error: invalid type, expected: string")]
  ExpectedString,
  #[error("serde_v8 error: invalid type, expected: array")]
  ExpectedArray,
  #[error("serde_v8 error: invalid type, expected: map")]
  ExpectedMap,
  #[error("serde_v8 error: invalid type, expected: enum")]
  ExpectedEnum,
  #[error("serde_v8 error: invalid type, expected: object")]
  ExpectedObject,
  #[error("serde_v8 error: invalid type, expected: buffer")]
  ExpectedBuffer,
  #[error("serde_v8 error: invalid type, expected: detachable")]
  ExpectedDetachable,
  #[error("serde_v8 error: invalid type, expected: external")]
  ExpectedExternal,
  #[error("serde_v8 error: invalid type, expected: bigint")]
  ExpectedBigInt,

  #[error("serde_v8 error: invalid type, expected: utf8")]
  ExpectedUtf8,
  #[error("serde_v8 error: invalid type, expected: latin1")]
  ExpectedLatin1,

  #[error("serde_v8 error: unsupported type")]
  UnsupportedType,

  #[error("serde_v8 error: length mismatch, got: {0}, expected: {1}")]
  LengthMismatch(usize, usize),
}

impl serde::ser::Error for Error {
  fn custom<T: Display>(msg: T) -> Self {
    Error::Message(msg.to_string())
  }
}

impl serde::de::Error for Error {
  fn custom<T: Display>(msg: T) -> Self {
    Error::Message(msg.to_string())
  }
}