pear-errors 1.0.0 → 1.0.1
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/index.js +5 -0
- package/package.json +1 -1
- package/test/index.test.js +50 -0
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
|
|
@@ -95,6 +96,10 @@ function ERR_UNSTAGED (msg, info = null) {
|
|
|
95
96
|
return new PearError(msg, ERR_UNSTAGED, info)
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
function ERR_NOT_FOUND (msg, info = null) {
|
|
100
|
+
return new PearError(msg, ERR_NOT_FOUND, info)
|
|
101
|
+
}
|
|
102
|
+
|
|
98
103
|
function ERR_DIR_NONEMPTY (msg, info = null) {
|
|
99
104
|
return new PearError(msg, ERR_DIR_NONEMPTY, info)
|
|
100
105
|
}
|
package/package.json
CHANGED
package/test/index.test.js
CHANGED
|
@@ -64,3 +64,53 @@ test('known() with extra prefixes does not break', (t) => {
|
|
|
64
64
|
t.ok(Array.isArray(list))
|
|
65
65
|
t.ok(list.every(n => n.startsWith('ERR_')))
|
|
66
66
|
})
|
|
67
|
+
|
|
68
|
+
test('known function with default prefix', async function (t) {
|
|
69
|
+
t.plan(1)
|
|
70
|
+
|
|
71
|
+
const knownErrors = PearError.known()
|
|
72
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('known function with custom prefix', async function (t) {
|
|
76
|
+
t.plan(1)
|
|
77
|
+
|
|
78
|
+
const knownErrors = PearError.known('ERR_INVALID')
|
|
79
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('known function with multiple prefixes', async function (t) {
|
|
83
|
+
t.plan(1)
|
|
84
|
+
|
|
85
|
+
const knownErrors = PearError.known('ERR_INVALID', 'ERR_PERMISSION')
|
|
86
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('known function with more than two prefixes', async function (t) {
|
|
90
|
+
t.plan(1)
|
|
91
|
+
|
|
92
|
+
const knownErrors = PearError.known('ERR_INVALID', 'ERR_PERMISSION', 'ERR_INTERNAL')
|
|
93
|
+
t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('known function with no matching prefix', async function (t) {
|
|
97
|
+
t.plan(2)
|
|
98
|
+
|
|
99
|
+
const knownErrors = PearError.known('ERR_NON_EXISTENT')
|
|
100
|
+
t.ok(Array.isArray(knownErrors))
|
|
101
|
+
t.is(knownErrors.length, 0)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('captureStackTrace filters out PearError frame', async function (t) {
|
|
105
|
+
t.plan(2)
|
|
106
|
+
|
|
107
|
+
const pearErr = PearError.ERR_INVALID_INPUT('invalid input')
|
|
108
|
+
|
|
109
|
+
t.is(pearErr.stack.includes('PearError'), false)
|
|
110
|
+
|
|
111
|
+
function ERR_CUSTOM (msg) {
|
|
112
|
+
return new Error(msg, ERR_CUSTOM)
|
|
113
|
+
}
|
|
114
|
+
const customErr = ERR_CUSTOM('custom error')
|
|
115
|
+
t.is(customErr.stack.includes('ERR_CUSTOM'), true)
|
|
116
|
+
})
|