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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Redacted guest decode errors.
use super::GuestDecodeField;
use crate::plugin::{PluginCapabilityShape, WorkspacePathError};
use std::fmt::{Display, Formatter};
/// Guest decode failure with redacted payload data.
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
#[non_exhaustive]
pub enum GuestDecodeError {
/// Byte field exceeded its configured cap.
PayloadTooLarge {
/// Field name.
field: GuestDecodeField,
/// Observed bytes.
size: u64,
/// Accepted bytes.
max: u64,
},
/// String field was not UTF-8.
MalformedUtf8 {
/// Field name.
field: GuestDecodeField,
/// Observed bytes.
size: u64,
},
/// Count exceeded runtime or host limits.
CountTooLarge {
/// Field name.
field: GuestDecodeField,
/// Observed value.
value: u64,
/// Accepted value.
max: u64,
},
/// Range start was after range end.
ReversedRange {
/// Field name.
field: GuestDecodeField,
/// Start byte index.
start: u64,
/// End byte index.
end: u64,
},
/// Range exceeded runtime or host limits.
RangeTooLarge {
/// Field name.
field: GuestDecodeField,
/// Start byte index.
start: u64,
/// End byte index.
end: u64,
/// Accepted end byte index.
max: u64,
},
/// Capability name is not in the current WIT vocabulary.
UnknownCapability {
/// Capability-name byte length.
byte_len: usize,
},
/// Workspace capability omitted its path.
MissingWorkspacePath {
/// Capability shape.
capability: PluginCapabilityShape,
},
/// Scalar capability included a path field.
UnexpectedWorkspacePath {
/// Capability shape.
capability: PluginCapabilityShape,
},
/// Workspace path failed Alma path validation.
InvalidWorkspacePath {
/// Field name.
field: GuestDecodeField,
/// Path validation error.
source: WorkspacePathError,
},
}
impl Display for GuestDecodeError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::PayloadTooLarge { field, size, max } => {
write!(formatter, "guest field {field} is {size} bytes, max {max}")
}
Self::MalformedUtf8 { field, size } => {
write!(formatter, "guest field {field} is not UTF-8, {size} bytes")
}
Self::CountTooLarge { field, value, max } => {
write!(formatter, "guest count {field} is {value}, max {max}")
}
Self::ReversedRange { field, start, end } => {
write!(
formatter,
"guest range {field} has start {start} after end {end}"
)
}
Self::RangeTooLarge {
field,
start,
end,
max,
} => write!(
formatter,
"guest range {field} is {start}..{end}, max end {max}"
),
Self::UnknownCapability { byte_len } => {
write!(
formatter,
"guest capability is unknown, {byte_len} name bytes"
)
}
Self::MissingWorkspacePath { capability } => {
write!(formatter, "{capability} requires a workspace path")
}
Self::UnexpectedWorkspacePath { capability } => {
write!(formatter, "{capability} does not accept a workspace path")
}
Self::InvalidWorkspacePath { field, source } => {
write!(
formatter,
"guest workspace path {field} is invalid: {source}"
)
}
}
}
}