Skip to content

Commit 10f2c31

Browse files
fix: Export error code type union to get typesense for error handling.
1 parent eeeb2f9 commit 10f2c31

9 files changed

Lines changed: 47 additions & 28 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ about: Create a report to help us improve
44
title: ''
55
labels: ''
66
assignees: ''
7-
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

1312
**To Reproduce**
1413
Steps to reproduce the behavior:
14+
1515
1. Go to '...'
1616
2. Click on '....'
1717
3. Scroll down to '....'
@@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
2424
If applicable, add screenshots to help explain your problem.
2525

2626
**Desktop (please complete the following information):**
27-
- OS: [e.g. iOS]
28-
- Browser [e.g. chrome, safari]
29-
- Version [e.g. 22]
27+
28+
- OS: [e.g. iOS]
29+
- Browser [e.g. chrome, safari]
30+
- Version [e.g. 22]
3031

3132
**Smartphone (please complete the following information):**
32-
- Device: [e.g. iPhone6]
33-
- OS: [e.g. iOS8.1]
34-
- Browser [e.g. stock browser, safari]
35-
- Version [e.g. 22]
33+
34+
- Device: [e.g. iPhone6]
35+
- OS: [e.g. iOS8.1]
36+
- Browser [e.g. stock browser, safari]
37+
- Version [e.g. 22]
3638

3739
**Additional context**
3840
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ about: Suggest an idea for this project
44
title: ''
55
labels: ''
66
assignees: ''
7-
87
---
98

109
**Is your feature request related to a problem? Please describe.**

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://jsr.io/schema/config-file.v1.json",
33
"name": "@sovereignbase/bytecodec",
4-
"version": "1.5.0",
4+
"version": "1.5.1",
55
"exports": "./src/index.ts",
66
"publish": {
77
"include": [

src/.errors/class.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* All structured error codes thrown by the bytecodec.
19+
*/
1720
export type BytecodecErrorCode =
1821
| 'BASE64_DECODER_UNAVAILABLE'
1922
| 'BASE64_ENCODER_UNAVAILABLE'
@@ -38,9 +41,21 @@ export type BytecodecErrorCode =
3841
| 'Z85_INVALID_CHARACTER'
3942
| 'Z85_INVALID_LENGTH'
4043

44+
/**
45+
* Error type used by the bytecodec helpers to expose a stable error code.
46+
*/
4147
export class BytecodecError extends Error {
48+
/**
49+
* Machine-readable error code for programmatic handling.
50+
*/
4251
readonly code: BytecodecErrorCode
4352

53+
/**
54+
* Creates a new bytecodec error with a package-prefixed message.
55+
*
56+
* @param code Stable error code describing the failure category.
57+
* @param message Optional human-readable detail appended to the package prefix.
58+
*/
4459
constructor(code: BytecodecErrorCode, message?: string) {
4560
const detail = message ?? code
4661
super(`{@sovereignbase/bytecodec} ${detail}`)

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export type ByteSource =
5656
| ArrayBufferView
5757
| number[]
5858

59+
export type { BytecodecErrorCode } from './.errors/class.js'
60+
5961
export {
6062
/***/
6163
fromBase64String,

test/e2e/runsInBrowsers/run.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ async function waitForServer(baseURL, child) {
4242

4343
while (Date.now() - startedAt < 10_000) {
4444
if (child.exitCode !== null)
45-
throw new Error(`browser test server exited early with code ${child.exitCode}`)
45+
throw new Error(
46+
`browser test server exited early with code ${child.exitCode}`
47+
)
4648

4749
try {
4850
const response = await fetch(baseURL)
@@ -83,10 +85,8 @@ async function main() {
8385
})
8486
})
8587

86-
if (result.signal)
87-
process.exitCode = 1
88-
else if (result.code !== 0)
89-
process.exitCode = result.code ?? 1
88+
if (result.signal) process.exitCode = 1
89+
else if (result.code !== 0) process.exitCode = result.code ?? 1
9090
} finally {
9191
if (server.exitCode === null) {
9292
server.kill('SIGTERM')

test/e2e/runsInBrowsers/runner.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import * as api from '/dist/index.js'
2-
import {
3-
printResults,
4-
runBytecodecSuite,
5-
} from '../shared/suite.mjs'
2+
import { printResults, runBytecodecSuite } from '../shared/suite.mjs'
63

74
const results = await runBytecodecSuite(api, { label: 'browser esm' })
85
printResults(results)

test/e2e/runsInCloudflareWorkers/run.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ const workerEntry = resolve(
2424
'runsInCloudflareWorkers',
2525
'worker.mjs'
2626
)
27-
const wranglerBin = resolve(root, 'node_modules', 'wrangler', 'bin', 'wrangler.js')
27+
const wranglerBin = resolve(
28+
root,
29+
'node_modules',
30+
'wrangler',
31+
'bin',
32+
'wrangler.js'
33+
)
2834

2935
function withTimeout(promise, timeoutMs, name) {
3036
let timer
@@ -111,7 +117,9 @@ async function fetchWorkerResults(url, child, logLines) {
111117
if (
112118
error instanceof TypeError ||
113119
(error instanceof Error &&
114-
/fetch failed|ECONNREFUSED|ENOTFOUND|socket hang up/i.test(error.message))
120+
/fetch failed|ECONNREFUSED|ENOTFOUND|socket hang up/i.test(
121+
error.message
122+
))
115123
) {
116124
await delay(POLL_INTERVAL_MS)
117125
continue

test/e2e/runsInDeno/run.mjs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import { spawnSync } from 'node:child_process'
44
const script = resolve(process.cwd(), 'test', 'e2e', 'runsInDeno', 'runner.mjs')
55
const result =
66
process.platform === 'win32'
7-
? spawnSync(
8-
'pwsh',
9-
['-NoProfile', '-Command', `deno run "${script}"`],
10-
{
11-
stdio: 'inherit',
12-
}
13-
)
7+
? spawnSync('pwsh', ['-NoProfile', '-Command', `deno run "${script}"`], {
8+
stdio: 'inherit',
9+
})
1410
: spawnSync('deno', ['run', script], {
1511
stdio: 'inherit',
1612
})

0 commit comments

Comments
 (0)