UNPKG

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