UNPKG

4.96 kBJavaScriptView Raw
1
2
3/**
4 * Error codes from libuv.
5 * @enum {number}
6 */
7var codes = {
8 UNKNOWN: {
9 errno: -1,
10 message: 'unknown error'
11 },
12 OK: {
13 errno: 0,
14 message: 'success'
15 },
16 EOF: {
17 errno: 1,
18 message: 'end of file'
19 },
20 EADDRINFO: {
21 errno: 2,
22 message: 'getaddrinfo error'
23 },
24 EACCES: {
25 errno: 3,
26 message: 'permission denied'
27 },
28 EAGAIN: {
29 errno: 4,
30 message: 'resource temporarily unavailable'
31 },
32 EADDRINUSE: {
33 errno: 5,
34 message: 'address already in use'
35 },
36 EADDRNOTAVAIL: {
37 errno: 6,
38 message: 'address not available'
39 },
40 EAFNOSUPPORT: {
41 errno: 7,
42 message: 'address family not supported'
43 },
44 EALREADY: {
45 errno: 8,
46 message: 'connection already in progress'
47 },
48 EBADF: {
49 errno: 9,
50 message: 'bad file descriptor'
51 },
52 EBUSY: {
53 errno: 10,
54 message: 'resource busy or locked'
55 },
56 ECONNABORTED: {
57 errno: 11,
58 message: 'software caused connection abort'
59 },
60 ECONNREFUSED: {
61 errno: 12,
62 message: 'connection refused'
63 },
64 ECONNRESET: {
65 errno: 13,
66 message: 'connection reset by peer'
67 },
68 EDESTADDRREQ: {
69 errno: 14,
70 message: 'destination address required'
71 },
72 EFAULT: {
73 errno: 15,
74 message: 'bad address in system call argument'
75 },
76 EHOSTUNREACH: {
77 errno: 16,
78 message: 'host is unreachable'
79 },
80 EINTR: {
81 errno: 17,
82 message: 'interrupted system call'
83 },
84 EINVAL: {
85 errno: 18,
86 message: 'invalid argument'
87 },
88 EISCONN: {
89 errno: 19,
90 message: 'socket is already connected'
91 },
92 EMFILE: {
93 errno: 20,
94 message: 'too many open files'
95 },
96 EMSGSIZE: {
97 errno: 21,
98 message: 'message too long'
99 },
100 ENETDOWN: {
101 errno: 22,
102 message: 'network is down'
103 },
104 ENETUNREACH: {
105 errno: 23,
106 message: 'network is unreachable'
107 },
108 ENFILE: {
109 errno: 24,
110 message: 'file table overflow'
111 },
112 ENOBUFS: {
113 errno: 25,
114 message: 'no buffer space available'
115 },
116 ENOMEM: {
117 errno: 26,
118 message: 'not enough memory'
119 },
120 ENOTDIR: {
121 errno: 27,
122 message: 'not a directory'
123 },
124 EISDIR: {
125 errno: 28,
126 message: 'illegal operation on a directory'
127 },
128 ENONET: {
129 errno: 29,
130 message: 'machine is not on the network'
131 },
132 ENOTCONN: {
133 errno: 31,
134 message: 'socket is not connected'
135 },
136 ENOTSOCK: {
137 errno: 32,
138 message: 'socket operation on non-socket'
139 },
140 ENOTSUP: {
141 errno: 33,
142 message: 'operation not supported on socket'
143 },
144 ENOENT: {
145 errno: 34,
146 message: 'no such file or directory'
147 },
148 ENOSYS: {
149 errno: 35,
150 message: 'function not implemented'
151 },
152 EPIPE: {
153 errno: 36,
154 message: 'broken pipe'
155 },
156 EPROTO: {
157 errno: 37,
158 message: 'protocol error'
159 },
160 EPROTONOSUPPORT: {
161 errno: 38,
162 message: 'protocol not supported'
163 },
164 EPROTOTYPE: {
165 errno: 39,
166 message: 'protocol wrong type for socket'
167 },
168 ETIMEDOUT: {
169 errno: 40,
170 message: 'connection timed out'
171 },
172 ECHARSET: {
173 errno: 41,
174 message: 'invalid Unicode character'
175 },
176 EAIFAMNOSUPPORT: {
177 errno: 42,
178 message: 'address family for hostname not supported'
179 },
180 EAISERVICE: {
181 errno: 44,
182 message: 'servname not supported for ai_socktype'
183 },
184 EAISOCKTYPE: {
185 errno: 45,
186 message: 'ai_socktype not supported'
187 },
188 ESHUTDOWN: {
189 errno: 46,
190 message: 'cannot send after transport endpoint shutdown'
191 },
192 EEXIST: {
193 errno: 47,
194 message: 'file already exists'
195 },
196 ESRCH: {
197 errno: 48,
198 message: 'no such process'
199 },
200 ENAMETOOLONG: {
201 errno: 49,
202 message: 'name too long'
203 },
204 EPERM: {
205 errno: 50,
206 message: 'operation not permitted'
207 },
208 ELOOP: {
209 errno: 51,
210 message: 'too many symbolic links encountered'
211 },
212 EXDEV: {
213 errno: 52,
214 message: 'cross-device link not permitted'
215 },
216 ENOTEMPTY: {
217 errno: 53,
218 message: 'directory not empty'
219 },
220 ENOSPC: {
221 errno: 54,
222 message: 'no space left on device'
223 },
224 EIO: {
225 errno: 55,
226 message: 'i/o error'
227 },
228 EROFS: {
229 errno: 56,
230 message: 'read-only file system'
231 },
232 ENODEV: {
233 errno: 57,
234 message: 'no such device'
235 },
236 ESPIPE: {
237 errno: 58,
238 message: 'invalid seek'
239 },
240 ECANCELED: {
241 errno: 59,
242 message: 'peration canceled'
243 }
244};
245
246
247
248/**
249 * Create an error.
250 * @param {string} code Error code.
251 * @param {string} path Path (optional).
252 * @constructor
253 */
254function FSError(code, path) {
255 if (!codes.hasOwnProperty(code)) {
256 throw new Error('Programmer error, invalid error code: ' + code);
257 }
258 Error.call(this);
259 var details = codes[code];
260 var message = code + ', ' + details.message;
261 if (path) {
262 message += ' \'' + path + '\'';
263 }
264 this.message = message;
265 this.code = code;
266 this.errno = details.errno;
267 Error.captureStackTrace(this, FSError);
268}
269FSError.prototype = new Error();
270
271
272/**
273 * Error constructor.
274 */
275exports = module.exports = FSError;