node-netlink 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -2
- package/dist/lib/constants.d.ts +47 -0
- package/dist/lib/constants.js +118 -0
- package/dist/lib/errno.d.ts +9 -0
- package/dist/lib/errno.js +27 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/index.js +52 -0
- package/dist/lib/message.d.ts +45 -0
- package/dist/lib/message.js +130 -0
- package/dist/lib/netlink-socket.d.ts +74 -0
- package/dist/lib/netlink-socket.js +314 -0
- package/dist/lib/po6-transport.d.ts +30 -0
- package/dist/lib/po6-transport.js +175 -0
- package/dist/lib/structures.d.ts +171 -0
- package/dist/lib/structures.js +88 -0
- package/package.json +38 -12
- package/.eslintrc +0 -90
- package/lib/error.js +0 -50
- package/lib/index.js +0 -259
- package/lib/parser.js +0 -55
- package/lib/structures.js +0 -21
- package/samples/test.js +0 -11
- package/test/base.js +0 -20
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type TAbi } from "ya-struct";
|
|
2
|
+
declare const sockaddrNlDefinition: {
|
|
3
|
+
readonly type: "struct";
|
|
4
|
+
readonly packed: false;
|
|
5
|
+
readonly fixedAbi: {};
|
|
6
|
+
readonly fields: readonly [{
|
|
7
|
+
readonly name: "nl_family";
|
|
8
|
+
readonly definition: {
|
|
9
|
+
readonly type: "c-type";
|
|
10
|
+
readonly cType: "unsigned short";
|
|
11
|
+
readonly fixedAbi: {};
|
|
12
|
+
};
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "nl_pad";
|
|
15
|
+
readonly definition: {
|
|
16
|
+
readonly type: "c-type";
|
|
17
|
+
readonly cType: "unsigned short";
|
|
18
|
+
readonly fixedAbi: {};
|
|
19
|
+
};
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "nl_pid";
|
|
22
|
+
readonly definition: {
|
|
23
|
+
readonly type: "integer";
|
|
24
|
+
readonly sizeInBits: 32;
|
|
25
|
+
readonly signed: false;
|
|
26
|
+
readonly fixedAbi: {};
|
|
27
|
+
};
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "nl_groups";
|
|
30
|
+
readonly definition: {
|
|
31
|
+
readonly type: "integer";
|
|
32
|
+
readonly sizeInBits: 32;
|
|
33
|
+
readonly signed: false;
|
|
34
|
+
readonly fixedAbi: {};
|
|
35
|
+
};
|
|
36
|
+
}];
|
|
37
|
+
};
|
|
38
|
+
declare const nlmsghdrDefinition: {
|
|
39
|
+
readonly type: "struct";
|
|
40
|
+
readonly packed: false;
|
|
41
|
+
readonly fixedAbi: {};
|
|
42
|
+
readonly fields: readonly [{
|
|
43
|
+
readonly name: "nlmsg_len";
|
|
44
|
+
readonly definition: {
|
|
45
|
+
readonly type: "integer";
|
|
46
|
+
readonly sizeInBits: 32;
|
|
47
|
+
readonly signed: false;
|
|
48
|
+
readonly fixedAbi: {};
|
|
49
|
+
};
|
|
50
|
+
}, {
|
|
51
|
+
readonly name: "nlmsg_type";
|
|
52
|
+
readonly definition: {
|
|
53
|
+
readonly type: "integer";
|
|
54
|
+
readonly sizeInBits: 16;
|
|
55
|
+
readonly signed: false;
|
|
56
|
+
readonly fixedAbi: {};
|
|
57
|
+
};
|
|
58
|
+
}, {
|
|
59
|
+
readonly name: "nlmsg_flags";
|
|
60
|
+
readonly definition: {
|
|
61
|
+
readonly type: "integer";
|
|
62
|
+
readonly sizeInBits: 16;
|
|
63
|
+
readonly signed: false;
|
|
64
|
+
readonly fixedAbi: {};
|
|
65
|
+
};
|
|
66
|
+
}, {
|
|
67
|
+
readonly name: "nlmsg_seq";
|
|
68
|
+
readonly definition: {
|
|
69
|
+
readonly type: "integer";
|
|
70
|
+
readonly sizeInBits: 32;
|
|
71
|
+
readonly signed: false;
|
|
72
|
+
readonly fixedAbi: {};
|
|
73
|
+
};
|
|
74
|
+
}, {
|
|
75
|
+
readonly name: "nlmsg_pid";
|
|
76
|
+
readonly definition: {
|
|
77
|
+
readonly type: "integer";
|
|
78
|
+
readonly sizeInBits: 32;
|
|
79
|
+
readonly signed: false;
|
|
80
|
+
readonly fixedAbi: {};
|
|
81
|
+
};
|
|
82
|
+
}];
|
|
83
|
+
};
|
|
84
|
+
declare const nlmsgerrDefinition: {
|
|
85
|
+
readonly type: "struct";
|
|
86
|
+
readonly packed: false;
|
|
87
|
+
readonly fixedAbi: {};
|
|
88
|
+
readonly fields: readonly [{
|
|
89
|
+
readonly name: "error";
|
|
90
|
+
readonly definition: {
|
|
91
|
+
readonly type: "c-type";
|
|
92
|
+
readonly cType: "int";
|
|
93
|
+
readonly fixedAbi: {};
|
|
94
|
+
};
|
|
95
|
+
}, {
|
|
96
|
+
readonly name: "msg";
|
|
97
|
+
readonly definition: {
|
|
98
|
+
readonly type: "struct";
|
|
99
|
+
readonly packed: false;
|
|
100
|
+
readonly fixedAbi: {};
|
|
101
|
+
readonly fields: readonly [{
|
|
102
|
+
readonly name: "nlmsg_len";
|
|
103
|
+
readonly definition: {
|
|
104
|
+
readonly type: "integer";
|
|
105
|
+
readonly sizeInBits: 32;
|
|
106
|
+
readonly signed: false;
|
|
107
|
+
readonly fixedAbi: {};
|
|
108
|
+
};
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "nlmsg_type";
|
|
111
|
+
readonly definition: {
|
|
112
|
+
readonly type: "integer";
|
|
113
|
+
readonly sizeInBits: 16;
|
|
114
|
+
readonly signed: false;
|
|
115
|
+
readonly fixedAbi: {};
|
|
116
|
+
};
|
|
117
|
+
}, {
|
|
118
|
+
readonly name: "nlmsg_flags";
|
|
119
|
+
readonly definition: {
|
|
120
|
+
readonly type: "integer";
|
|
121
|
+
readonly sizeInBits: 16;
|
|
122
|
+
readonly signed: false;
|
|
123
|
+
readonly fixedAbi: {};
|
|
124
|
+
};
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "nlmsg_seq";
|
|
127
|
+
readonly definition: {
|
|
128
|
+
readonly type: "integer";
|
|
129
|
+
readonly sizeInBits: 32;
|
|
130
|
+
readonly signed: false;
|
|
131
|
+
readonly fixedAbi: {};
|
|
132
|
+
};
|
|
133
|
+
}, {
|
|
134
|
+
readonly name: "nlmsg_pid";
|
|
135
|
+
readonly definition: {
|
|
136
|
+
readonly type: "integer";
|
|
137
|
+
readonly sizeInBits: 32;
|
|
138
|
+
readonly signed: false;
|
|
139
|
+
readonly fixedAbi: {};
|
|
140
|
+
};
|
|
141
|
+
}];
|
|
142
|
+
};
|
|
143
|
+
}];
|
|
144
|
+
};
|
|
145
|
+
declare const createNetlinkStructuresFor: ({ abi }: {
|
|
146
|
+
abi: TAbi;
|
|
147
|
+
}) => {
|
|
148
|
+
abi: TAbi;
|
|
149
|
+
sockaddrNl: any;
|
|
150
|
+
nlmsghdr: any;
|
|
151
|
+
nlmsgerr: any;
|
|
152
|
+
};
|
|
153
|
+
type TNetlinkStructures = ReturnType<typeof createNetlinkStructuresFor>;
|
|
154
|
+
declare const hostStructures: {
|
|
155
|
+
abi: TAbi;
|
|
156
|
+
sockaddrNl: any;
|
|
157
|
+
nlmsghdr: any;
|
|
158
|
+
nlmsgerr: any;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Formats a struct sockaddr_nl, e.g. to bind() a netlink socket.
|
|
162
|
+
*/
|
|
163
|
+
declare const formatNetlinkAddress: ({ address, structures }: {
|
|
164
|
+
address: {
|
|
165
|
+
nl_pid: bigint;
|
|
166
|
+
nl_groups: bigint;
|
|
167
|
+
};
|
|
168
|
+
structures?: TNetlinkStructures;
|
|
169
|
+
}) => any;
|
|
170
|
+
export { sockaddrNlDefinition, nlmsghdrDefinition, nlmsgerrDefinition, createNetlinkStructuresFor, hostStructures, formatNetlinkAddress, };
|
|
171
|
+
export type { TNetlinkStructures, };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { define, /*type TAbi */} from "ya-struct";
|
|
2
|
+
import { hostAbi } from "po6";
|
|
3
|
+
import { AF_NETLINK } from "./constants.js";
|
|
4
|
+
|
|
5
|
+
// struct sockaddr_nl from <linux/netlink.h>
|
|
6
|
+
const sockaddrNlDefinition = {
|
|
7
|
+
type: "struct",
|
|
8
|
+
packed: false,
|
|
9
|
+
fixedAbi: {},
|
|
10
|
+
fields: [
|
|
11
|
+
{ name: "nl_family", definition: { type: "c-type", cType: "unsigned short", fixedAbi: {} } },
|
|
12
|
+
{ name: "nl_pad", definition: { type: "c-type", cType: "unsigned short", fixedAbi: {} } },
|
|
13
|
+
{ name: "nl_pid", definition: { type: "integer", sizeInBits: 32, signed: false, fixedAbi: {} } },
|
|
14
|
+
{ name: "nl_groups", definition: { type: "integer", sizeInBits: 32, signed: false, fixedAbi: {} } },
|
|
15
|
+
],
|
|
16
|
+
} /*as const*/;
|
|
17
|
+
|
|
18
|
+
// struct nlmsghdr from <linux/netlink.h>
|
|
19
|
+
const nlmsghdrDefinition = {
|
|
20
|
+
type: "struct",
|
|
21
|
+
packed: false,
|
|
22
|
+
fixedAbi: {},
|
|
23
|
+
fields: [
|
|
24
|
+
{ name: "nlmsg_len", definition: { type: "integer", sizeInBits: 32, signed: false, fixedAbi: {} } },
|
|
25
|
+
{ name: "nlmsg_type", definition: { type: "integer", sizeInBits: 16, signed: false, fixedAbi: {} } },
|
|
26
|
+
{ name: "nlmsg_flags", definition: { type: "integer", sizeInBits: 16, signed: false, fixedAbi: {} } },
|
|
27
|
+
{ name: "nlmsg_seq", definition: { type: "integer", sizeInBits: 32, signed: false, fixedAbi: {} } },
|
|
28
|
+
{ name: "nlmsg_pid", definition: { type: "integer", sizeInBits: 32, signed: false, fixedAbi: {} } },
|
|
29
|
+
],
|
|
30
|
+
} /*as const*/;
|
|
31
|
+
|
|
32
|
+
// struct nlmsgerr from <linux/netlink.h>, the payload of NLMSG_ERROR
|
|
33
|
+
const nlmsgerrDefinition = {
|
|
34
|
+
type: "struct",
|
|
35
|
+
packed: false,
|
|
36
|
+
fixedAbi: {},
|
|
37
|
+
fields: [
|
|
38
|
+
{ name: "error", definition: { type: "c-type", cType: "int", fixedAbi: {} } },
|
|
39
|
+
{ name: "msg", definition: nlmsghdrDefinition },
|
|
40
|
+
],
|
|
41
|
+
} /*as const*/;
|
|
42
|
+
|
|
43
|
+
const sockaddrNl = define({ definition: sockaddrNlDefinition });
|
|
44
|
+
const nlmsghdr = define({ definition: nlmsghdrDefinition });
|
|
45
|
+
const nlmsgerr = define({ definition: nlmsgerrDefinition });
|
|
46
|
+
|
|
47
|
+
const createNetlinkStructuresFor = ({ abi }/*: { abi: TAbi }*/) => {
|
|
48
|
+
return {
|
|
49
|
+
abi,
|
|
50
|
+
sockaddrNl: sockaddrNl.parser({ abi }),
|
|
51
|
+
nlmsghdr: nlmsghdr.parser({ abi }),
|
|
52
|
+
nlmsgerr: nlmsgerr.parser({ abi }),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*type TNetlinkStructures = ReturnType<typeof createNetlinkStructuresFor>;*/
|
|
57
|
+
|
|
58
|
+
const hostStructures = createNetlinkStructuresFor({ abi: hostAbi });
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Formats a struct sockaddr_nl, e.g. to bind() a netlink socket.
|
|
62
|
+
*/
|
|
63
|
+
const formatNetlinkAddress = ({ address, structures = hostStructures }/*: {
|
|
64
|
+
address: { nl_pid: bigint, nl_groups: bigint },
|
|
65
|
+
structures?: TNetlinkStructures,
|
|
66
|
+
}*/) => {
|
|
67
|
+
return structures.sockaddrNl.format({
|
|
68
|
+
value: {
|
|
69
|
+
nl_family: AF_NETLINK,
|
|
70
|
+
nl_pad: 0n,
|
|
71
|
+
...address,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
sockaddrNlDefinition,
|
|
78
|
+
nlmsghdrDefinition,
|
|
79
|
+
nlmsgerrDefinition,
|
|
80
|
+
|
|
81
|
+
createNetlinkStructuresFor,
|
|
82
|
+
hostStructures,
|
|
83
|
+
formatNetlinkAddress,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/*export type {
|
|
87
|
+
TNetlinkStructures,
|
|
88
|
+
};*/
|
package/package.json
CHANGED
|
@@ -1,26 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "0.0.5",
|
|
2
3
|
"name": "node-netlink",
|
|
3
4
|
"type": "module",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
"description": "The netlink protocol for Node.js on Linux, on top of sockets you own",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "dist/lib/index.js",
|
|
10
|
+
"scripts": {},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@eslint/js": "^10.0.1",
|
|
13
|
+
"@k13engineering/eslint-rules": "^0.0.6",
|
|
14
|
+
"@k13engineering/releasetool": "^0.0.5",
|
|
15
|
+
"@k13engineering/uv-poll": "^0.0.6",
|
|
16
|
+
"@types/mocha": "^10.0.10",
|
|
17
|
+
"@types/node": "^25.6.0",
|
|
18
|
+
"buffer2address": "^0.1.1",
|
|
19
|
+
"c8": "^11.0.0",
|
|
20
|
+
"deno-node": "^0.0.12",
|
|
21
|
+
"mocha": "^12.0.2",
|
|
22
|
+
"npm-check-updates": "^20.0.2",
|
|
23
|
+
"syscall-napi": "^0.2.2",
|
|
24
|
+
"typescript": "^6.0.3"
|
|
10
25
|
},
|
|
11
26
|
"dependencies": {
|
|
12
|
-
"po6
|
|
13
|
-
"ya-struct": "^0.0.
|
|
27
|
+
"po6": "^0.1.0",
|
|
28
|
+
"ya-struct": "^0.0.17"
|
|
14
29
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"eslint": "^7.32.0",
|
|
18
|
-
"mocha": "^9.1.3"
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
19
32
|
},
|
|
20
33
|
"repository": {
|
|
21
34
|
"type": "git",
|
|
22
35
|
"url": "git+https://github.com/k13-engineering/node-netlink.git"
|
|
23
36
|
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"netlink",
|
|
39
|
+
"linux",
|
|
40
|
+
"socket",
|
|
41
|
+
"rtnetlink",
|
|
42
|
+
"typescript"
|
|
43
|
+
],
|
|
44
|
+
"os": [
|
|
45
|
+
"linux"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=24"
|
|
49
|
+
},
|
|
24
50
|
"author": "Simon Kadisch",
|
|
25
51
|
"license": "LGPL 2.1",
|
|
26
52
|
"bugs": {
|
package/.eslintrc
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parserOptions": {
|
|
3
|
-
"ecmaVersion": 2021,
|
|
4
|
-
"sourceType": "module",
|
|
5
|
-
"requireConfigFile": false
|
|
6
|
-
},
|
|
7
|
-
"env": {
|
|
8
|
-
"node": true,
|
|
9
|
-
"es2020": true
|
|
10
|
-
},
|
|
11
|
-
"rules": {
|
|
12
|
-
"global-require": "off",
|
|
13
|
-
"quote-props": ["warn", "consistent-as-needed"],
|
|
14
|
-
"quotes": ["error", "double", { "allowTemplateLiterals": true }],
|
|
15
|
-
"no-plusplus": "error",
|
|
16
|
-
"no-nested-ternary": "error",
|
|
17
|
-
"no-multiple-empty-lines": "error",
|
|
18
|
-
"no-inline-comments": "error",
|
|
19
|
-
"no-lonely-if": "error",
|
|
20
|
-
"no-array-constructor": "error",
|
|
21
|
-
"no-delete-var": "error",
|
|
22
|
-
"no-param-reassign": "error",
|
|
23
|
-
"no-return-assign": "error",
|
|
24
|
-
"no-import-assign": "error",
|
|
25
|
-
"no-multi-assign": "error",
|
|
26
|
-
"keyword-spacing": "error",
|
|
27
|
-
"max-len": [ "warn", { "code": 140 } ],
|
|
28
|
-
"max-params": ["error", 4],
|
|
29
|
-
"max-statements": ["error", 15],
|
|
30
|
-
"no-loss-of-precision": "error",
|
|
31
|
-
"no-unreachable-loop": "error",
|
|
32
|
-
"require-atomic-updates": "error",
|
|
33
|
-
"complexity": ["error", 4],
|
|
34
|
-
"max-statements-per-line": ["error", { "max": 1 }],
|
|
35
|
-
"no-tabs": "error",
|
|
36
|
-
"no-underscore-dangle": "error",
|
|
37
|
-
"no-negated-condition": "error",
|
|
38
|
-
"no-use-before-define": "error",
|
|
39
|
-
"no-shadow": "error",
|
|
40
|
-
"no-labels": "error",
|
|
41
|
-
"no-throw-literal": "error",
|
|
42
|
-
"default-case": "error",
|
|
43
|
-
"default-case-last": "error",
|
|
44
|
-
"no-caller": "error",
|
|
45
|
-
"no-eval": "error",
|
|
46
|
-
"no-implied-eval": "error",
|
|
47
|
-
"no-new": "error",
|
|
48
|
-
"no-new-func": "error",
|
|
49
|
-
"no-new-object": "error",
|
|
50
|
-
"no-new-wrappers": "error",
|
|
51
|
-
"no-useless-concat": "error",
|
|
52
|
-
"no-unused-vars": ["error", {"ignoreRestSiblings": true}],
|
|
53
|
-
"array-bracket-newline": ["error", "consistent"],
|
|
54
|
-
"func-names": ["error", "never"],
|
|
55
|
-
"func-style": ["error", "expression", { "allowArrowFunctions": true }],
|
|
56
|
-
"max-depth": ["error", 4],
|
|
57
|
-
"arrow-parens": "error",
|
|
58
|
-
"no-confusing-arrow": "error",
|
|
59
|
-
"prefer-const": "error",
|
|
60
|
-
"rest-spread-spacing": ["error", "never"],
|
|
61
|
-
"template-curly-spacing": ["error", "never"],
|
|
62
|
-
"prefer-rest-params": "error",
|
|
63
|
-
"prefer-spread": "error",
|
|
64
|
-
"prefer-template": "error",
|
|
65
|
-
"object-shorthand": ["error", "properties"],
|
|
66
|
-
"no-var": "error",
|
|
67
|
-
"no-useless-computed-key": "error",
|
|
68
|
-
"array-callback-return": "error",
|
|
69
|
-
"consistent-return": "error",
|
|
70
|
-
"dot-notation": "error",
|
|
71
|
-
"eqeqeq": "error",
|
|
72
|
-
"no-eq-null": "error",
|
|
73
|
-
"no-implicit-coercion": "error",
|
|
74
|
-
"no-multi-spaces": "error",
|
|
75
|
-
"no-proto": "error",
|
|
76
|
-
"yoda": "error",
|
|
77
|
-
"indent": ["error", 2],
|
|
78
|
-
"object-curly-spacing": [ "error", "always" ],
|
|
79
|
-
"object-curly-newline": ["error", { "consistent": true, "multiline": true }],
|
|
80
|
-
"space-before-blocks": "error",
|
|
81
|
-
"space-before-function-paren": [ "error", "always" ],
|
|
82
|
-
"spaced-comment": "error",
|
|
83
|
-
"no-whitespace-before-property": "error",
|
|
84
|
-
"brace-style": ["error", "1tbs", { "allowSingleLine": false }],
|
|
85
|
-
"eol-last": ["error", "always"],
|
|
86
|
-
"func-call-spacing": ["error", "never"],
|
|
87
|
-
"semi": ["error", "always"]
|
|
88
|
-
},
|
|
89
|
-
"extends": "eslint:recommended"
|
|
90
|
-
}
|
package/lib/error.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const knownErrors = {
|
|
2
|
-
EPERM: {
|
|
3
|
-
code: 1,
|
|
4
|
-
message: "Operation not permitted",
|
|
5
|
-
},
|
|
6
|
-
ENOENT: {
|
|
7
|
-
code: 2,
|
|
8
|
-
message: "No such file or directory",
|
|
9
|
-
},
|
|
10
|
-
EAGAIN: {
|
|
11
|
-
code: 11,
|
|
12
|
-
message: "Resource temporarily unavailable",
|
|
13
|
-
},
|
|
14
|
-
EEXIST: {
|
|
15
|
-
code: 17,
|
|
16
|
-
message: "File already exists",
|
|
17
|
-
},
|
|
18
|
-
ENODEV: {
|
|
19
|
-
code: 19,
|
|
20
|
-
message: "No such device",
|
|
21
|
-
},
|
|
22
|
-
EINVAL: {
|
|
23
|
-
code: 22,
|
|
24
|
-
message: "Invalid argument",
|
|
25
|
-
},
|
|
26
|
-
ENOTSUP: {
|
|
27
|
-
code: 48,
|
|
28
|
-
message: "Operation not supported",
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const createFromErrorCode = ({ errorCode, message }) => {
|
|
33
|
-
const knownErrorKey = Object.keys(knownErrors).find((key) => {
|
|
34
|
-
return knownErrors[key].code === errorCode;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (knownErrorKey) {
|
|
38
|
-
const knownError = knownErrors[knownErrorKey];
|
|
39
|
-
const errorObject = new Error(`${message ? `${message}: ` : ""}${knownError.message}`);
|
|
40
|
-
errorObject.code = knownError.code;
|
|
41
|
-
errorObject.errno = errorCode;
|
|
42
|
-
return errorObject;
|
|
43
|
-
} else {
|
|
44
|
-
return new Error(`${message ? `${message}: ` : ""}unknown error code ${errorCode}`);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default {
|
|
49
|
-
createFromErrorCode,
|
|
50
|
-
};
|