1 | 'use strict';
|
2 |
|
3 | const uvBinding = process.binding('uv');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const codes = {};
|
9 |
|
10 | uvBinding.getErrorMap().forEach(function(value, errno) {
|
11 | const code = value[0];
|
12 | const message = value[1];
|
13 | codes[code] = {errno: errno, message: message};
|
14 | });
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function FSError(code, path) {
|
23 | if (!codes.hasOwnProperty(code)) {
|
24 | throw new Error('Programmer error, invalid error code: ' + code);
|
25 | }
|
26 | Error.call(this);
|
27 | const details = codes[code];
|
28 | let message = code + ', ' + details.message;
|
29 | if (path) {
|
30 | message += " '" + path + "'";
|
31 | }
|
32 | this.message = message;
|
33 | this.code = code;
|
34 | this.errno = details.errno;
|
35 | if (path !== undefined) {
|
36 | this.path = path;
|
37 | }
|
38 | Error.captureStackTrace(this, FSError);
|
39 | }
|
40 | FSError.prototype = new Error();
|
41 | FSError.codes = codes;
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | function AbortError() {
|
48 | Error.call(this);
|
49 | this.code = 'ABORT_ERR';
|
50 | this.name = 'AbortError';
|
51 | Error.captureStackTrace(this, AbortError);
|
52 | }
|
53 | AbortError.prototype = new Error();
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | exports.FSError = FSError;
|
59 |
|
60 |
|
61 |
|
62 | exports.AbortError = AbortError;
|