-
Notifications
You must be signed in to change notification settings - Fork 9
/
error.go
434 lines (349 loc) · 11.1 KB
/
error.go
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
package wasi
import (
"fmt"
"syscall"
)
// Errno are the error codes returned by functions.
//
// Not all of these error codes are returned by the functions provided by this
// API; some are used in higher-level library layers, and others are provided
// merely for alignment with POSIX.
type Errno uint16
const (
// ESUCCESS indicates that no error occurred (system call completed
// successfully).
ESUCCESS Errno = iota
// E2BIG means an argument list is too long.
E2BIG
// EACCES means permission is denied.
EACCES
// EADDRINUSE means an address is already in use.
EADDRINUSE
// EADDRNOTAVAIL means an address is not available.
EADDRNOTAVAIL
// EAFNOSUPPORT means an address family is not supported by a protocol family.
EAFNOSUPPORT
// EAGAIN means the caller should try again.
EAGAIN
// EALREADY means a socket already connected
EALREADY
// EBADF means bad file number.
EBADF
// EBADMSG indicates that the caller is trying to read an unreadable message.
EBADMSG
// EBUSY means a device or resource busy.
EBUSY
// ECANCELED means an operation was canceled.
ECANCELED
// ECHILD means no child processes.
ECHILD
// ECONNABORTED means a connection was aborted.
ECONNABORTED
// ECONNREFUSED means connection was refused.
ECONNREFUSED
// ECONNRESET means a connection was reset by peer.
ECONNRESET
// EDEADLK indicates a deadlock condition.
EDEADLK
// EDESTADDRREQ means a destination address is required.
EDESTADDRREQ
// EDOM means a math argument is out of domain of func.
EDOM
// EDQUOT means a quota was exceeded.
EDQUOT
// EEXIST means a file exists.
EEXIST
// EFAULT means bad address.
EFAULT
// EFBIG indicates a file is too large.
EFBIG
// EHOSTUNREACH means a host is unreachable.
EHOSTUNREACH
// EIDRM means identifier removed.
EIDRM
// EILSEQ indicates an illegal byte sequence
EILSEQ
// EINPROGRESS means a connection is already in progress.
EINPROGRESS
// EINTR means a system call was interrupted.
EINTR
// EINVAL means an argument was invalid.
EINVAL
// EIO means an I/O error occurred.
EIO
// EISCONN means a socket is already connected.
EISCONN
// EISDIR means a file is a directory.
EISDIR
// ELOOP indicates that there are too many symbolic links.
ELOOP
// EMFILE indicates that there are too many open files
EMFILE
// EMLINK indicates that there are too many links
EMLINK
// EMSGSIZE means a message is too long.
EMSGSIZE
// EMULTIHOP means a multihop was attempted.
EMULTIHOP
// ENAMETOOLONG means a file name is too long.
ENAMETOOLONG
// ENETDOWN means a network interface is not configured.
ENETDOWN
// ENETRESET means a network was dropped connection on reset.
ENETRESET
// ENETUNREACH means a network is unreachable.
ENETUNREACH
// ENFILE means a file table overflow occurred.
ENFILE
// ENOBUFS means that no buffer space is available.
ENOBUFS
// ENODEV means no such device.
ENODEV
// ENOENT means no such file or directory.
ENOENT
// ENOEXEC means an exec format error.
ENOEXEC
// ENOLCK means that there are no record locks available
ENOLCK
// ENOLINK means the link has been severed.
ENOLINK
// ENOMEM means out of memory.
ENOMEM
// ENOMSG means that there is no message of desired type.
ENOMSG
// ENOPROTOOPT means a protocol is not available.
ENOPROTOOPT
// ENOSPC means that there is no space left on a device.
ENOSPC
// ENOSYS means not implemented.
ENOSYS
// ENOTCONN means a socket is not connected.
ENOTCONN
// ENOTDIR means a file is not a directory
ENOTDIR
// ENOTEMPTY means a directory is not empty.
ENOTEMPTY
// ENOTRECOVERABLE means state is not recoverable.
ENOTRECOVERABLE
// ENOTSOCK means a socket operation was attempted on a non-socket.
ENOTSOCK
// ENOTSUP means not supported.
ENOTSUP
// ENOTTY means not a typewriter.
ENOTTY
// ENXIO means no such device or address.
ENXIO
// EOVERFLOW means the value is too large for defined data type.
EOVERFLOW
// EOWNERDEAD means an owner died.
EOWNERDEAD
// EPERM means an operation is not permitted.
EPERM
// EPIPE means broken pipe.
EPIPE
// EPROTO means a protocol error ocurred.
EPROTO
// EPROTONOSUPPORT means a protocol is not supported.
EPROTONOSUPPORT
// EPROTOTYPE means that a protocol is the wrong type for socket.
EPROTOTYPE
// ERANGE means a math result is not representable.
ERANGE
// EROFS means a file system is read-only.
EROFS
// ESPIPE means a seek is illegal.
ESPIPE
// ESRCH means no such process.
ESRCH
// ESTALE means a file handle is stale.
ESTALE
// ETIMEDOUT means a connection timed out.
ETIMEDOUT
// ETXTBSY means text file busy.
ETXTBSY
// EXDEV means cross-device link.
EXDEV
// ENOTCAPABLE means capabilities are insufficient.
ENOTCAPABLE
)
// MakeErrno converts a Go error to a WASI errno value in a way that is portable
// across platforms.
func MakeErrno(err error) Errno { return makeErrno(err) }
func (e Errno) Error() string {
if i := int(e); i >= 0 && i < len(errorStrings) {
return errorStrings[i]
}
return fmt.Sprintf("Unknown Error (%d)", int(e))
}
func (e Errno) Name() string {
if i := int(e); i >= 0 && i < len(errorNames) {
return errorNames[i]
}
return fmt.Sprintf("errno(%d)", int(e))
}
// Syscall convers the error to a native error number of the host platform.
//
// The method does the inverse of passing the syscall.Errno value to
// wasi.MakeErrno tho some error numbers may differ on the host platform,
// therefore there is no guarantee that the wasi.Errno value obtained by a
// call to wasi.MakeErrno will yield the same syscall.Errno returned by this
// method.
func (e Errno) Syscall() syscall.Errno { return errnoToSyscall(e) }
var errorStrings = [...]string{
ESUCCESS: "OK",
E2BIG: "Argument list too long",
EACCES: "Permission denied",
EADDRINUSE: "Address already in use",
EADDRNOTAVAIL: "Address not available",
EAFNOSUPPORT: "Address family not supported by protocol family",
EAGAIN: "Try again",
EALREADY: "Socket already connected",
EBADF: "Bad file number",
EBADMSG: "Trying to read unreadable message",
EBUSY: "Device or resource busy",
ECANCELED: "Operation canceled.",
ECHILD: "No child processes",
ECONNABORTED: "Connection aborted",
ECONNREFUSED: "Connection refused",
ECONNRESET: "Connection reset by peer",
EDEADLK: "Deadlock condition",
EDESTADDRREQ: "Destination address required",
EDOM: "Math arg out of domain of func",
EDQUOT: "Quota exceeded",
EEXIST: "File exists",
EFAULT: "Bad address",
EFBIG: "File too large",
EHOSTUNREACH: "Host is unreachable",
EIDRM: "Identifier removed",
EILSEQ: "Illegal byte sequence",
EINPROGRESS: "Connection already in progress",
EINTR: "Interrupted system call",
EINVAL: "Invalid argument",
EIO: "I/O error",
EISCONN: "Socket is already connected",
EISDIR: "Is a directory",
ELOOP: "Too many symbolic links",
EMFILE: "Too many open files",
EMLINK: "Too many links",
EMSGSIZE: "Message too long",
EMULTIHOP: "Multihop attempted",
ENAMETOOLONG: "File name too long",
ENETDOWN: "Network interface is not configured",
ENETRESET: "Network dropped connection on reset",
ENETUNREACH: "Network is unreachable",
ENFILE: "File table overflow",
ENOBUFS: "No buffer space available",
ENODEV: "No such device",
ENOENT: "No such file or directory",
ENOEXEC: "Exec format error",
ENOLCK: "No record locks available",
ENOLINK: "The link has been severed",
ENOMEM: "Out of memory",
ENOMSG: "No message of desired type",
ENOPROTOOPT: "Protocol not available",
ENOSPC: "No space left on device",
ENOSYS: "Not implemented",
ENOTCONN: "Socket is not connected",
ENOTDIR: "Not a directory",
ENOTEMPTY: "Directory not empty",
ENOTRECOVERABLE: "State not recoverable",
ENOTSOCK: "Socket operation on non-socket",
ENOTSUP: "Not supported",
ENOTTY: "Not a typewriter",
ENXIO: "No such device or address",
EOVERFLOW: "Value too large for defined data type",
EOWNERDEAD: "Owner died",
EPERM: "Operation not permitted",
EPIPE: "Broken pipe",
EPROTO: "Protocol error",
EPROTONOSUPPORT: "Unknown protocol",
EPROTOTYPE: "Protocol wrong type for socket",
ERANGE: "Math result not representable",
EROFS: "Read-only file system",
ESPIPE: "Illegal seek",
ESRCH: "No such process",
ESTALE: "Stale file handle",
ETIMEDOUT: "Connection timed out",
ETXTBSY: "Text file busy",
EXDEV: "Cross-device link",
ENOTCAPABLE: "Capabilities insufficient",
}
var errorNames = [...]string{
ESUCCESS: "ESUCCESS",
E2BIG: "E2BIG",
EACCES: "EACCES",
EADDRINUSE: "EADDRINUSE",
EADDRNOTAVAIL: "EADDRNOTAVAIL",
EAFNOSUPPORT: "EAFNOSUPPORT",
EAGAIN: "EAGAIN",
EALREADY: "EALREADY",
EBADF: "EBADF",
EBADMSG: "EBADMSG",
EBUSY: "EBUSY",
ECANCELED: "ECANCELED",
ECHILD: "ECHILD",
ECONNABORTED: "ECONNABORTED",
ECONNREFUSED: "ECONNREFUSED",
ECONNRESET: "ECONNRESET",
EDEADLK: "EDEADLK",
EDESTADDRREQ: "EDESTADDRREQ",
EDOM: "EDOM",
EDQUOT: "EDQUOT",
EEXIST: "EEXIST",
EFAULT: "EFAULT",
EFBIG: "EFBIG",
EHOSTUNREACH: "EHOSTUNREACH",
EIDRM: "EIDRM",
EILSEQ: "EILSEQ",
EINPROGRESS: "EINPROGRESS",
EINTR: "EINTR",
EINVAL: "EINVAL",
EIO: "EIO",
EISCONN: "EISCONN",
EISDIR: "EISDIR",
ELOOP: "ELOOP",
EMFILE: "EMFILE",
EMLINK: "EMLINK",
EMSGSIZE: "EMSGSIZE",
EMULTIHOP: "EMULTIHOP",
ENAMETOOLONG: "ENAMETOOLONG",
ENETDOWN: "ENETDOWN",
ENETRESET: "ENETRESET",
ENETUNREACH: "ENETUNREACH",
ENFILE: "ENFILE",
ENOBUFS: "ENOBUFS",
ENODEV: "ENODEV",
ENOENT: "ENOENT",
ENOEXEC: "ENOEXEC",
ENOLCK: "ENOLCK",
ENOLINK: "ENOLINK",
ENOMEM: "ENOMEM",
ENOMSG: "ENOMSG",
ENOPROTOOPT: "ENOPROTOOPT",
ENOSPC: "ENOSPC",
ENOSYS: "ENOSYS",
ENOTCONN: "ENOTCONN",
ENOTDIR: "ENOTDIR",
ENOTEMPTY: "ENOTEMPTY",
ENOTRECOVERABLE: "ENOTRECOVERABLE",
ENOTSOCK: "ENOTSOCK",
ENOTSUP: "ENOTSUP",
ENOTTY: "ENOTTY",
ENXIO: "ENXIO",
EOVERFLOW: "EOVERFLOW",
EOWNERDEAD: "EOWNERDEAD",
EPERM: "EPERM",
EPIPE: "EPIPE",
EPROTO: "EPROTO",
EPROTONOSUPPORT: "EPROTONOSUPPORT",
EPROTOTYPE: "EPROTOTYPE",
ERANGE: "ERANGE",
EROFS: "EROFS",
ESPIPE: "ESPIPE",
ESRCH: "ESRCH",
ESTALE: "ESTALE",
ETIMEDOUT: "ETIMEDOUT",
ETXTBSY: "ETXTBSY",
EXDEV: "EXDEV",
ENOTCAPABLE: "ENOTCAPABLE",
}