bless_plugins/wasi/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum WasiError {
5    #[error("Argument list too long.")]
6    TooBig = 1,
7    #[error("Permission denied.")]
8    Access,
9    #[error("Address not available.")]
10    AddrNotUse,
11    #[error("Address not available.")]
12    AddrNotAvail,
13    #[error("Address family not supported..")]
14    AfNoSupport,
15    #[error("Resource unavailable, or operation would block.")]
16    Again,
17    #[error("Connection already in progress.")]
18    Already,
19    #[error("Bad file descriptor.")]
20    Badf,
21    #[error("Bad message.")]
22    Badmsg,
23    #[error("Device or resource busy.")]
24    Busy,
25    #[error("Operation canceled.")]
26    Canceled,
27    #[error("No child processes.")]
28    Child,
29    #[error("Connection aborted.")]
30    Connaborted,
31    #[error("Connection refused.")]
32    ConnRefused,
33    #[error("Connection reset.")]
34    ConnReset,
35    #[error("Resource deadlock would occur.")]
36    Deadlk,
37    #[error("Destination address required.")]
38    Destaddrreq,
39    #[error("Mathematics argument out of domain of function.")]
40    Dom,
41    #[error("Reserved.")]
42    Dquot,
43    #[error("File exists.")]
44    Exist,
45    #[error("Bad address.")]
46    Fault,
47    #[error("File too large.")]
48    Fbig,
49    #[error("Host is unreachable.")]
50    Hostunreach,
51    #[error("Identifier removed.")]
52    Idrm,
53    #[error("Illegal byte sequence.")]
54    Ilseq,
55    #[error("Operation in progress.")]
56    Inprogress,
57    #[error("Interrupted function.")]
58    Intr,
59    #[error("Invalid argument.")]
60    Inval,
61    #[error("I/O error.")]
62    Io,
63    #[error("Socket is connected.")]
64    Isconn,
65    #[error("Is a directory.")]
66    Isdir,
67    #[error("Too many levels of symbolic links.")]
68    Loop,
69    #[error("File descriptor value too large.")]
70    Mfile,
71    #[error("Too many links.")]
72    Mlink,
73    #[error("Message too large.")]
74    Msgsize,
75    #[error("Reserved.")]
76    Multihop,
77    #[error("Filename too long.")]
78    Nametoolong,
79    #[error("Network is down.")]
80    Netdown,
81    #[error("Connection aborted by network.")]
82    Netreset,
83    #[error("Network unreachable.")]
84    Netunreach,
85    #[error("Too many files open in system.")]
86    Nfile,
87    #[error("No buffer space available.")]
88    Nobufs,
89    #[error("No such device.")]
90    Nodev,
91    #[error("No such file or directory.")]
92    Noent,
93    #[error("Executable file format error.")]
94    Noexec,
95    #[error("No locks available.")]
96    Nolck,
97    #[error("Reserved.")]
98    Nolink,
99    #[error("Not enough space.")]
100    Nomem,
101    #[error("No message of the desired type.")]
102    Nomsg,
103    #[error("Protocol not available.")]
104    Noprotoopt,
105    #[error("No space left on device.")]
106    Nospc,
107    #[error("Function not supported.")]
108    Nosys,
109    #[error("The socket is not connected.")]
110    Notconn,
111    #[error("Not a directory or a symbolic link to a directory.")]
112    Notdir,
113    #[error("Directory not empty.")]
114    Notempty,
115    #[error("State not recoverable.")]
116    Notrecoverable,
117    #[error("Not a socket.")]
118    Notsock,
119    #[error("Not supported, or operation not supported on socket.")]
120    Notsup,
121    #[error("Inappropriate I/O control operation.")]
122    Notty,
123    #[error("No such device or address.")]
124    Nxio,
125    #[error("Value too large to be stored in data type.")]
126    Overflow,
127    #[error("Previous owner died.")]
128    Ownerdead,
129    #[error("Operation not permitted.")]
130    Perm,
131    #[error("Broken pipe.")]
132    Pipe,
133    #[error("Protocol error.")]
134    Proto,
135    #[error("Protocol not supported.")]
136    Protonosupport,
137    #[error("Protocol wrong type for socket.")]
138    Prototype,
139    #[error("Result too large.")]
140    Range,
141    #[error("Read-only file system.")]
142    Rofs,
143    #[error("Invalid seek.")]
144    Spipe,
145    #[error("No such process.")]
146    Srch,
147    #[error("Reserved.")]
148    Stale,
149    #[error("Connection timed out.")]
150    Timedout,
151    #[error("Text file busy.")]
152    Txtbsy,
153    #[error("Cross-device link.")]
154    Xdev,
155    #[error("Extension: Capabilities insufficient.")]
156    Notcapable,
157}
158
159impl From<i32> for WasiError {
160    fn from(code: i32) -> Self {
161        match code {
162            1 => WasiError::TooBig,
163            2 => WasiError::Access,
164            3 => WasiError::AddrNotUse,
165            4 => WasiError::AddrNotAvail,
166            5 => WasiError::AfNoSupport,
167            6 => WasiError::Again,
168            7 => WasiError::Already,
169            8 => WasiError::Badf,
170            9 => WasiError::Badmsg,
171            10 => WasiError::Busy,
172            11 => WasiError::Canceled,
173            12 => WasiError::Child,
174            13 => WasiError::Connaborted,
175            14 => WasiError::ConnRefused,
176            15 => WasiError::ConnReset,
177            16 => WasiError::Deadlk,
178            17 => WasiError::Destaddrreq,
179            18 => WasiError::Dom,
180            19 => WasiError::Dquot,
181            20 => WasiError::Exist,
182            21 => WasiError::Fault,
183            22 => WasiError::Fbig,
184            23 => WasiError::Hostunreach,
185            24 => WasiError::Idrm,
186            25 => WasiError::Ilseq,
187            26 => WasiError::Inprogress,
188            27 => WasiError::Intr,
189            28 => WasiError::Inval,
190            29 => WasiError::Io,
191            30 => WasiError::Isconn,
192            31 => WasiError::Isdir,
193            32 => WasiError::Loop,
194            33 => WasiError::Mfile,
195            34 => WasiError::Mlink,
196            35 => WasiError::Msgsize,
197            36 => WasiError::Multihop,
198            37 => WasiError::Nametoolong,
199            38 => WasiError::Netdown,
200            39 => WasiError::Netreset,
201            40 => WasiError::Netunreach,
202            41 => WasiError::Nfile,
203            42 => WasiError::Nobufs,
204            43 => WasiError::Nodev,
205            44 => WasiError::Noent,
206            45 => WasiError::Noexec,
207            46 => WasiError::Nolck,
208            47 => WasiError::Nolink,
209            48 => WasiError::Nomem,
210            49 => WasiError::Nomsg,
211            50 => WasiError::Noprotoopt,
212            51 => WasiError::Nospc,
213            52 => WasiError::Nosys,
214            53 => WasiError::Notconn,
215            54 => WasiError::Notdir,
216            55 => WasiError::Notempty,
217            56 => WasiError::Notrecoverable,
218            57 => WasiError::Notsock,
219            58 => WasiError::Notsup,
220            59 => WasiError::Notty,
221            60 => WasiError::Nxio,
222            61 => WasiError::Overflow,
223            62 => WasiError::Ownerdead,
224            63 => WasiError::Perm,
225            64 => WasiError::Pipe,
226            65 => WasiError::Proto,
227            66 => WasiError::Protonosupport,
228            67 => WasiError::Prototype,
229            68 => WasiError::Range,
230            69 => WasiError::Rofs,
231            70 => WasiError::Spipe,
232            71 => WasiError::Srch,
233            72 => WasiError::Stale,
234            73 => WasiError::Timedout,
235            74 => WasiError::Txtbsy,
236            75 => WasiError::Xdev,
237            76 => WasiError::Notcapable,
238            _ => unimplemented!("WasiError code: {}", code),
239        }
240    }
241}