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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::Val;
use alloc::string::String;
use core::fmt;
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
Parse(String),
Val(Val),
Char(isize),
Str(Val),
Arr(Val),
Length(Val),
Round(Val),
FromJson(Val, String),
Has(Val, Val),
Keys(Val),
Iter(Val),
Neg(Val),
MathOp(Val, jaq_parse::MathOp, Val),
Index(Val),
IndexWith(Val, Val),
IndexOutOfBounds(isize),
Int(Val),
SliceAssign(Val),
PathExp,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self {
Self::Parse(s) => s.fmt(f),
Self::Val(Val::Str(s)) => s.fmt(f),
Self::Val(v) => v.fmt(f),
Self::Char(i) => write!(f, "cannot use {i} as character"),
Self::Str(v) => write!(f, "cannot use {v} as string"),
Self::Arr(v) => write!(f, "cannot use {v} as array"),
Self::Length(v) => write!(f, "{v} has no length"),
Self::Round(v) => write!(f, "cannot round {v}"),
Self::FromJson(v, why) => write!(f, "cannot parse {v} as JSON: {why}"),
Self::Keys(v) => write!(f, "{v} has no keys"),
Self::Has(v, k) => write!(f, "cannot check whether {v} has key {k}"),
Self::Iter(v) => write!(f, "cannot iterate over {v}"),
Self::Neg(v) => write!(f, "cannot negate {v}"),
Self::MathOp(l, op, r) => write!(f, "cannot calculate {l} {op} {r}"),
Self::Index(v) => write!(f, "cannot index {v}"),
Self::IndexWith(v, i) => write!(f, "cannot index {v} with {i}"),
Self::IndexOutOfBounds(i) => write!(f, "index {i} is out of bounds"),
Self::Int(v) => write!(f, "cannot use {v} as integer"),
Self::SliceAssign(v) => write!(f, "cannot assign non-array ({v}) to an array slice"),
Self::PathExp => write!(f, "invalid path expression"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}