pear-errors 1.0.0 → 1.0.2
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/.gitattributes +1 -0
- package/.github/workflows/integrate.yml +28 -0
- package/.github/workflows/publish.yml +17 -0
- package/.prettierrc +1 -0
- package/README.md +1 -1
- package/index.js +33 -23
- package/package.json +25 -8
- package/test/all.js +1 -1
- package/test/index.test.js +64 -4
- package/.github/workflows/test.yml +0 -41
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Integrate
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
jobs:
|
|
8
|
+
lint:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
name: Lint
|
|
11
|
+
steps:
|
|
12
|
+
- uses: holepunchto/actions/node-base@v1
|
|
13
|
+
- run: npm run lint
|
|
14
|
+
test:
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
include:
|
|
18
|
+
- os: ubuntu-latest
|
|
19
|
+
platform: linux
|
|
20
|
+
- os: macos-latest
|
|
21
|
+
platform: darwin
|
|
22
|
+
- os: windows-latest
|
|
23
|
+
platform: win32
|
|
24
|
+
runs-on: ${{ matrix.os }}
|
|
25
|
+
name: Test / ${{ matrix.platform }}
|
|
26
|
+
steps:
|
|
27
|
+
- uses: holepunchto/actions/bare-base@v1
|
|
28
|
+
- run: npm test
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags:
|
|
5
|
+
- v*
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
contents: write
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: npm
|
|
14
|
+
name: Publish
|
|
15
|
+
steps:
|
|
16
|
+
- uses: holepunchto/actions/node-base@v1
|
|
17
|
+
- uses: holepunchto/actions/publish@v1
|
package/.prettierrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"prettier-config-holepunch"
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ class PearError extends Error {
|
|
|
12
12
|
static ERR_PERMISSION_REQUIRED = ERR_PERMISSION_REQUIRED
|
|
13
13
|
static ERR_INTERNAL_ERROR = ERR_INTERNAL_ERROR
|
|
14
14
|
static ERR_UNSTAGED = ERR_UNSTAGED
|
|
15
|
+
static ERR_NOT_FOUND = ERR_NOT_FOUND
|
|
15
16
|
static ERR_DIR_NONEMPTY = ERR_DIR_NONEMPTY
|
|
16
17
|
static ERR_OPERATION_FAILED = ERR_OPERATION_FAILED
|
|
17
18
|
static ERR_SECRET_NOT_FOUND = ERR_SECRET_NOT_FOUND
|
|
@@ -21,7 +22,7 @@ class PearError extends Error {
|
|
|
21
22
|
static ERR_UNKNOWN = ERR_UNKNOWN
|
|
22
23
|
static ERR_LEGACY = ERR_LEGACY
|
|
23
24
|
static known = known
|
|
24
|
-
constructor
|
|
25
|
+
constructor(msg, fn = PearError, info = null, stackless = false) {
|
|
25
26
|
super(msg)
|
|
26
27
|
this.code = fn.name
|
|
27
28
|
this.name = fn.name
|
|
@@ -31,87 +32,96 @@ class PearError extends Error {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
function known
|
|
35
|
-
return [
|
|
35
|
+
function known(prefix = 'ERR_', ...prefixes) {
|
|
36
|
+
return [
|
|
37
|
+
...Object.getOwnPropertyNames(PearError).filter((name) =>
|
|
38
|
+
name.startsWith(prefix)
|
|
39
|
+
),
|
|
40
|
+
...prefixes.flatMap((prefix) => known(prefix))
|
|
41
|
+
]
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
function ERR_INVALID_INPUT
|
|
44
|
+
function ERR_INVALID_INPUT(msg, info = null) {
|
|
39
45
|
return new PearError(msg, ERR_INVALID_INPUT, info)
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
function ERR_INVALID_LINK
|
|
48
|
+
function ERR_INVALID_LINK(msg, info = null) {
|
|
43
49
|
return new PearError(msg, ERR_INVALID_LINK, info)
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
function ERR_INVALID_APPLING
|
|
52
|
+
function ERR_INVALID_APPLING(msg, info = null) {
|
|
47
53
|
return new PearError(msg, ERR_INVALID_APPLING, info)
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
function ERR_INVALID_APP_NAME
|
|
56
|
+
function ERR_INVALID_APP_NAME(msg, info = null) {
|
|
51
57
|
return new PearError(msg, ERR_INVALID_APP_NAME, info)
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
function ERR_INVALID_APP_STORAGE
|
|
60
|
+
function ERR_INVALID_APP_STORAGE(msg, info = null) {
|
|
55
61
|
return new PearError(msg, ERR_INVALID_APP_STORAGE, info)
|
|
56
62
|
}
|
|
57
63
|
|
|
58
|
-
function ERR_INVALID_PROJECT_DIR
|
|
64
|
+
function ERR_INVALID_PROJECT_DIR(msg, info = null) {
|
|
59
65
|
return new PearError(msg, ERR_INVALID_PROJECT_DIR, info)
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
function ERR_INVALID_GC_RESOURCE
|
|
68
|
+
function ERR_INVALID_GC_RESOURCE(msg, info = null) {
|
|
63
69
|
return new PearError(msg, ERR_INVALID_GC_RESOURCE, info)
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
function ERR_INVALID_CONFIG
|
|
72
|
+
function ERR_INVALID_CONFIG(msg, info = null) {
|
|
67
73
|
return new PearError(msg, ERR_INVALID_CONFIG, info)
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
function ERR_INVALID_TEMPLATE
|
|
76
|
+
function ERR_INVALID_TEMPLATE(msg, info = null) {
|
|
71
77
|
return new PearError(msg, ERR_INVALID_TEMPLATE, info)
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
function ERR_PERMISSION_REQUIRED
|
|
80
|
+
function ERR_PERMISSION_REQUIRED(msg, info = {}) {
|
|
75
81
|
return new PearError(msg, ERR_PERMISSION_REQUIRED, info)
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
function ERR_SECRET_NOT_FOUND
|
|
84
|
+
function ERR_SECRET_NOT_FOUND(msg, info = null) {
|
|
79
85
|
return new PearError(msg, ERR_SECRET_NOT_FOUND, info)
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
function ERR_CONNECTION
|
|
88
|
+
function ERR_CONNECTION(msg, info = null) {
|
|
83
89
|
return new PearError(msg, ERR_CONNECTION, info)
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
function ERR_INVALID_MANIFEST
|
|
92
|
+
function ERR_INVALID_MANIFEST(msg, info = null) {
|
|
87
93
|
return new PearError(msg, ERR_INVALID_MANIFEST, info)
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
function ERR_INTERNAL_ERROR
|
|
96
|
+
function ERR_INTERNAL_ERROR(msg, info = null) {
|
|
91
97
|
return new PearError(msg, ERR_INTERNAL_ERROR, info)
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
function ERR_UNSTAGED
|
|
100
|
+
function ERR_UNSTAGED(msg, info = null) {
|
|
95
101
|
return new PearError(msg, ERR_UNSTAGED, info)
|
|
96
102
|
}
|
|
97
103
|
|
|
98
|
-
function
|
|
104
|
+
function ERR_NOT_FOUND(msg, info = null) {
|
|
105
|
+
return new PearError(msg, ERR_NOT_FOUND, info)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function ERR_DIR_NONEMPTY(msg, info = null) {
|
|
99
109
|
return new PearError(msg, ERR_DIR_NONEMPTY, info)
|
|
100
110
|
}
|
|
101
111
|
|
|
102
|
-
function ERR_OPERATION_FAILED
|
|
112
|
+
function ERR_OPERATION_FAILED(msg, info = {}) {
|
|
103
113
|
return new PearError(msg, ERR_OPERATION_FAILED, info)
|
|
104
114
|
}
|
|
105
115
|
|
|
106
|
-
function ERR_ASSERTION
|
|
116
|
+
function ERR_ASSERTION(msg, info = null) {
|
|
107
117
|
return new PearError(msg, ERR_ASSERTION, info)
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
function ERR_UNKNOWN
|
|
120
|
+
function ERR_UNKNOWN(msg, info = null) {
|
|
111
121
|
return new PearError(msg, ERR_UNKNOWN, info)
|
|
112
122
|
}
|
|
113
123
|
|
|
114
|
-
function ERR_LEGACY
|
|
124
|
+
function ERR_LEGACY(msg, info = null) {
|
|
115
125
|
return new PearError(msg, ERR_LEGACY, info, true)
|
|
116
126
|
}
|
|
117
127
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-errors",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "Pear Core Error Types",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
9
|
+
"format": "prettier --write .",
|
|
10
|
+
"lint": "prettier --check . && lunte",
|
|
11
|
+
"test": "npm run test:node && npm run test:bare",
|
|
12
|
+
"test:node": "brittle-node test/all.js",
|
|
13
|
+
"test:bare": "brittle-bare test/all.js",
|
|
14
|
+
"test:gen": "brittle -r test/all.js test/*.test.js"
|
|
13
15
|
},
|
|
14
16
|
"devDependencies": {
|
|
15
|
-
"brittle": "^3.
|
|
16
|
-
"
|
|
17
|
-
|
|
17
|
+
"brittle": "^3.5.0",
|
|
18
|
+
"lunte": "^1.0.0",
|
|
19
|
+
"prettier": "^3.6.2",
|
|
20
|
+
"prettier-config-holepunch": "^1.0.0"
|
|
21
|
+
},
|
|
22
|
+
"directories": {
|
|
23
|
+
"test": "test"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/holepunchto/pear-errors.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [],
|
|
30
|
+
"author": "",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/holepunchto/pear-errors/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/holepunchto/pear-errors#readme"
|
|
18
35
|
}
|
package/test/all.js
CHANGED
package/test/index.test.js
CHANGED
|
@@ -5,12 +5,16 @@ const PearError = require('..')
|
|
|
5
5
|
test('exports shape', (t) => {
|
|
6
6
|
t.is(typeof PearError, 'function')
|
|
7
7
|
t.is(typeof PearError.known, 'function')
|
|
8
|
-
const statics = Object.getOwnPropertyNames(PearError).filter(n =>
|
|
8
|
+
const statics = Object.getOwnPropertyNames(PearError).filter((n) =>
|
|
9
|
+
n.startsWith('ERR_')
|
|
10
|
+
)
|
|
9
11
|
t.ok(statics.length > 0)
|
|
10
12
|
})
|
|
11
13
|
|
|
12
14
|
test('known() lists all ERR_* statics', (t) => {
|
|
13
|
-
const statics = Object.getOwnPropertyNames(PearError).filter(n =>
|
|
15
|
+
const statics = Object.getOwnPropertyNames(PearError).filter((n) =>
|
|
16
|
+
n.startsWith('ERR_')
|
|
17
|
+
)
|
|
14
18
|
const listed = PearError.known()
|
|
15
19
|
t.alike(new Set(listed), new Set(statics))
|
|
16
20
|
})
|
|
@@ -48,7 +52,9 @@ test('stack vs stackless', (t) => {
|
|
|
48
52
|
})
|
|
49
53
|
|
|
50
54
|
test('all helpers return PearError instances with matching names', (t) => {
|
|
51
|
-
const names = Object.getOwnPropertyNames(PearError).filter(n =>
|
|
55
|
+
const names = Object.getOwnPropertyNames(PearError).filter((n) =>
|
|
56
|
+
n.startsWith('ERR_')
|
|
57
|
+
)
|
|
52
58
|
for (const n of names) {
|
|
53
59
|
const fn = PearError[n]
|
|
54
60
|
t.is(typeof fn, 'function')
|
|
@@ -62,5 +68,59 @@ test('all helpers return PearError instances with matching names', (t) => {
|
|
|
62
68
|
test('known() with extra prefixes does not break', (t) => {
|
|
63
69
|
const list = PearError.known('ERR_', 'NOPE_')
|
|
64
70
|
t.ok(Array.isArray(list))
|
|
65
|
-
t.ok(list.every(n => n.startsWith('ERR_')))
|
|
71
|
+
t.ok(list.every((n) => n.startsWith('ERR_')))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('known function with default prefix', async function (t) {
|
|
75
|
+
t.plan(1)
|
|
76
|
+
|
|
77
|
+
const knownErrors = PearError.known()
|
|
78
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('known function with custom prefix', async function (t) {
|
|
82
|
+
t.plan(1)
|
|
83
|
+
|
|
84
|
+
const knownErrors = PearError.known('ERR_INVALID')
|
|
85
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('known function with multiple prefixes', async function (t) {
|
|
89
|
+
t.plan(1)
|
|
90
|
+
|
|
91
|
+
const knownErrors = PearError.known('ERR_INVALID', 'ERR_PERMISSION')
|
|
92
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('known function with more than two prefixes', async function (t) {
|
|
96
|
+
t.plan(1)
|
|
97
|
+
|
|
98
|
+
const knownErrors = PearError.known(
|
|
99
|
+
'ERR_INVALID',
|
|
100
|
+
'ERR_PERMISSION',
|
|
101
|
+
'ERR_INTERNAL'
|
|
102
|
+
)
|
|
103
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('known function with no matching prefix', async function (t) {
|
|
107
|
+
t.plan(2)
|
|
108
|
+
|
|
109
|
+
const knownErrors = PearError.known('ERR_NON_EXISTENT')
|
|
110
|
+
t.ok(Array.isArray(knownErrors))
|
|
111
|
+
t.is(knownErrors.length, 0)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('captureStackTrace filters out PearError frame', async function (t) {
|
|
115
|
+
t.plan(2)
|
|
116
|
+
|
|
117
|
+
const pearErr = PearError.ERR_INVALID_INPUT('invalid input')
|
|
118
|
+
|
|
119
|
+
t.is(pearErr.stack.includes('PearError'), false)
|
|
120
|
+
|
|
121
|
+
function ERR_CUSTOM(msg) {
|
|
122
|
+
return new Error(msg, ERR_CUSTOM)
|
|
123
|
+
}
|
|
124
|
+
const customErr = ERR_CUSTOM('custom error')
|
|
125
|
+
t.is(customErr.stack.includes('ERR_CUSTOM'), true)
|
|
66
126
|
})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
name: Test
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [ main ]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [ main ]
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
test:
|
|
11
|
-
strategy:
|
|
12
|
-
matrix:
|
|
13
|
-
include:
|
|
14
|
-
- os: ubuntu-latest
|
|
15
|
-
platform: linux
|
|
16
|
-
arch: x64
|
|
17
|
-
|
|
18
|
-
- os: macos-latest
|
|
19
|
-
platform: darwin
|
|
20
|
-
arch: x64
|
|
21
|
-
|
|
22
|
-
- os: windows-latest
|
|
23
|
-
platform: win32
|
|
24
|
-
arch: x64
|
|
25
|
-
|
|
26
|
-
runs-on: ${{ matrix.os }}
|
|
27
|
-
name: ${{ matrix.platform }}-${{ matrix.arch }}
|
|
28
|
-
steps:
|
|
29
|
-
- uses: actions/checkout@v4
|
|
30
|
-
|
|
31
|
-
- name: Setup bare
|
|
32
|
-
run: npm i -g bare-runtime
|
|
33
|
-
|
|
34
|
-
- name: Install dependencies
|
|
35
|
-
run: npm i
|
|
36
|
-
|
|
37
|
-
- name: Lint
|
|
38
|
-
run: npm run lint
|
|
39
|
-
|
|
40
|
-
- name: Run tests
|
|
41
|
-
run: npm run cov
|