pear-errors 1.0.1 → 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 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
@@ -6,4 +6,4 @@
6
6
 
7
7
  # License
8
8
 
9
- Apache-2.0
9
+ Apache-2.0
package/index.js CHANGED
@@ -22,7 +22,7 @@ class PearError extends Error {
22
22
  static ERR_UNKNOWN = ERR_UNKNOWN
23
23
  static ERR_LEGACY = ERR_LEGACY
24
24
  static known = known
25
- constructor (msg, fn = PearError, info = null, stackless = false) {
25
+ constructor(msg, fn = PearError, info = null, stackless = false) {
26
26
  super(msg)
27
27
  this.code = fn.name
28
28
  this.name = fn.name
@@ -32,91 +32,96 @@ class PearError extends Error {
32
32
  }
33
33
  }
34
34
 
35
- function known (prefix = 'ERR_', ...prefixes) {
36
- return [...Object.getOwnPropertyNames(PearError).filter((name) => name.startsWith(prefix)), ...prefixes.flatMap((prefix) => known(prefix))]
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
+ ]
37
42
  }
38
43
 
39
- function ERR_INVALID_INPUT (msg, info = null) {
44
+ function ERR_INVALID_INPUT(msg, info = null) {
40
45
  return new PearError(msg, ERR_INVALID_INPUT, info)
41
46
  }
42
47
 
43
- function ERR_INVALID_LINK (msg, info = null) {
48
+ function ERR_INVALID_LINK(msg, info = null) {
44
49
  return new PearError(msg, ERR_INVALID_LINK, info)
45
50
  }
46
51
 
47
- function ERR_INVALID_APPLING (msg, info = null) {
52
+ function ERR_INVALID_APPLING(msg, info = null) {
48
53
  return new PearError(msg, ERR_INVALID_APPLING, info)
49
54
  }
50
55
 
51
- function ERR_INVALID_APP_NAME (msg, info = null) {
56
+ function ERR_INVALID_APP_NAME(msg, info = null) {
52
57
  return new PearError(msg, ERR_INVALID_APP_NAME, info)
53
58
  }
54
59
 
55
- function ERR_INVALID_APP_STORAGE (msg, info = null) {
60
+ function ERR_INVALID_APP_STORAGE(msg, info = null) {
56
61
  return new PearError(msg, ERR_INVALID_APP_STORAGE, info)
57
62
  }
58
63
 
59
- function ERR_INVALID_PROJECT_DIR (msg, info = null) {
64
+ function ERR_INVALID_PROJECT_DIR(msg, info = null) {
60
65
  return new PearError(msg, ERR_INVALID_PROJECT_DIR, info)
61
66
  }
62
67
 
63
- function ERR_INVALID_GC_RESOURCE (msg, info = null) {
68
+ function ERR_INVALID_GC_RESOURCE(msg, info = null) {
64
69
  return new PearError(msg, ERR_INVALID_GC_RESOURCE, info)
65
70
  }
66
71
 
67
- function ERR_INVALID_CONFIG (msg, info = null) {
72
+ function ERR_INVALID_CONFIG(msg, info = null) {
68
73
  return new PearError(msg, ERR_INVALID_CONFIG, info)
69
74
  }
70
75
 
71
- function ERR_INVALID_TEMPLATE (msg, info = null) {
76
+ function ERR_INVALID_TEMPLATE(msg, info = null) {
72
77
  return new PearError(msg, ERR_INVALID_TEMPLATE, info)
73
78
  }
74
79
 
75
- function ERR_PERMISSION_REQUIRED (msg, info = {}) {
80
+ function ERR_PERMISSION_REQUIRED(msg, info = {}) {
76
81
  return new PearError(msg, ERR_PERMISSION_REQUIRED, info)
77
82
  }
78
83
 
79
- function ERR_SECRET_NOT_FOUND (msg, info = null) {
84
+ function ERR_SECRET_NOT_FOUND(msg, info = null) {
80
85
  return new PearError(msg, ERR_SECRET_NOT_FOUND, info)
81
86
  }
82
87
 
83
- function ERR_CONNECTION (msg, info = null) {
88
+ function ERR_CONNECTION(msg, info = null) {
84
89
  return new PearError(msg, ERR_CONNECTION, info)
85
90
  }
86
91
 
87
- function ERR_INVALID_MANIFEST (msg, info = null) {
92
+ function ERR_INVALID_MANIFEST(msg, info = null) {
88
93
  return new PearError(msg, ERR_INVALID_MANIFEST, info)
89
94
  }
90
95
 
91
- function ERR_INTERNAL_ERROR (msg, info = null) {
96
+ function ERR_INTERNAL_ERROR(msg, info = null) {
92
97
  return new PearError(msg, ERR_INTERNAL_ERROR, info)
93
98
  }
94
99
 
95
- function ERR_UNSTAGED (msg, info = null) {
100
+ function ERR_UNSTAGED(msg, info = null) {
96
101
  return new PearError(msg, ERR_UNSTAGED, info)
97
102
  }
98
103
 
99
- function ERR_NOT_FOUND (msg, info = null) {
104
+ function ERR_NOT_FOUND(msg, info = null) {
100
105
  return new PearError(msg, ERR_NOT_FOUND, info)
101
106
  }
102
107
 
103
- function ERR_DIR_NONEMPTY (msg, info = null) {
108
+ function ERR_DIR_NONEMPTY(msg, info = null) {
104
109
  return new PearError(msg, ERR_DIR_NONEMPTY, info)
105
110
  }
106
111
 
107
- function ERR_OPERATION_FAILED (msg, info = {}) {
112
+ function ERR_OPERATION_FAILED(msg, info = {}) {
108
113
  return new PearError(msg, ERR_OPERATION_FAILED, info)
109
114
  }
110
115
 
111
- function ERR_ASSERTION (msg, info = null) {
116
+ function ERR_ASSERTION(msg, info = null) {
112
117
  return new PearError(msg, ERR_ASSERTION, info)
113
118
  }
114
119
 
115
- function ERR_UNKNOWN (msg, info = null) {
120
+ function ERR_UNKNOWN(msg, info = null) {
116
121
  return new PearError(msg, ERR_UNKNOWN, info)
117
122
  }
118
123
 
119
- function ERR_LEGACY (msg, info = null) {
124
+ function ERR_LEGACY(msg, info = null) {
120
125
  return new PearError(msg, ERR_LEGACY, info, true)
121
126
  }
122
127
 
package/package.json CHANGED
@@ -1,18 +1,35 @@
1
1
  {
2
2
  "name": "pear-errors",
3
- "version": "1.0.1",
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
- "test:gen": "brittle -r test/all.js test/*.test.js",
10
- "test": "brittle test/all.js",
11
- "lint": "standard",
12
- "cov": "brittle-bare --coverage test/all.js"
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.0.0",
16
- "standard": "^17.1.2"
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  runTests()
4
4
 
5
- async function runTests () {
5
+ async function runTests() {
6
6
  const test = (await import('brittle')).default
7
7
 
8
8
  test.pause()
@@ -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 => n.startsWith('ERR_'))
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 => n.startsWith('ERR_'))
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 => n.startsWith('ERR_'))
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,7 +68,7 @@ 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_')))
66
72
  })
67
73
 
68
74
  test('known function with default prefix', async function (t) {
@@ -89,7 +95,11 @@ test('known function with multiple prefixes', async function (t) {
89
95
  test('known function with more than two prefixes', async function (t) {
90
96
  t.plan(1)
91
97
 
92
- const knownErrors = PearError.known('ERR_INVALID', 'ERR_PERMISSION', 'ERR_INTERNAL')
98
+ const knownErrors = PearError.known(
99
+ 'ERR_INVALID',
100
+ 'ERR_PERMISSION',
101
+ 'ERR_INTERNAL'
102
+ )
93
103
  t.ok(Array.isArray(knownErrors) && knownErrors.length > 0)
94
104
  })
95
105
 
@@ -108,7 +118,7 @@ test('captureStackTrace filters out PearError frame', async function (t) {
108
118
 
109
119
  t.is(pearErr.stack.includes('PearError'), false)
110
120
 
111
- function ERR_CUSTOM (msg) {
121
+ function ERR_CUSTOM(msg) {
112
122
  return new Error(msg, ERR_CUSTOM)
113
123
  }
114
124
  const customErr = ERR_CUSTOM('custom error')
@@ -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