Skip to content

Commit 5e2ee59

Browse files
authored
refactor: Minor error changes (#98)
2 parents 177c998 + fab2503 commit 5e2ee59

18 files changed

+258
-163
lines changed

.github/workflows/release.yml

Lines changed: 101 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ name: Release
33
on:
44
push:
55
branches: [main]
6-
paths:
7-
- "jsr.json"
8-
- "package.json"
9-
- "CHANGELOG.md"
6+
tags: ["v*"]
107

118
permissions:
129
id-token: write
@@ -19,60 +16,106 @@ concurrency:
1916

2017
jobs:
2118
detect:
22-
if: github.repository == 'kasperrt/wiretyped'
19+
if: ${{ github.repository == 'kasperrt/wiretyped' && !(startsWith(github.ref, 'refs/tags/') && github.actor == 'github-actions[bot]') }}
2320
runs-on: ubuntu-latest
2421

2522
outputs:
2623
tag: ${{ steps.out.outputs.tag }}
2724
version: ${{ steps.out.outputs.version }}
28-
created: ${{ steps.out.outputs.created }}
25+
run: ${{ steps.out.outputs.run }}
26+
create_tag: ${{ steps.out.outputs.create_tag }}
2927

3028
steps:
3129
- name: Checkout
3230
uses: actions/checkout@v4
3331
with:
3432
fetch-depth: 0
3533

36-
- name: Read and validate versions
37-
id: ver
34+
- name: Determine tag/version
35+
id: meta
3836
shell: bash
3937
run: |
4038
set -euo pipefail
4139
42-
if [ ! -f "jsr.json" ]; then
43-
echo "ERROR: jsr.json not found"
44-
exit 1
45-
fi
46-
47-
if [ ! -f "package.json" ]; then
48-
echo "ERROR: package.json not found"
49-
exit 1
50-
fi
51-
52-
JSR_VERSION="$(jq -r '.version // empty' jsr.json)"
53-
PKG_VERSION="$(jq -r '.version // empty' package.json)"
54-
55-
if [ -z "$JSR_VERSION" ] || [ -z "$PKG_VERSION" ]; then
56-
echo "ERROR: Missing version in jsr.json or package.json"
57-
exit 1
58-
fi
59-
60-
if [ "$JSR_VERSION" != "$PKG_VERSION" ]; then
61-
echo "ERROR: Version mismatch!"
62-
echo " jsr.json : $JSR_VERSION"
63-
echo " package.json : $PKG_VERSION"
64-
exit 1
40+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
41+
TAG="${GITHUB_REF_NAME}"
42+
43+
if [[ "$TAG" != v* ]]; then
44+
echo "ERROR: Tag must start with 'v' (got: $TAG)"
45+
exit 1
46+
fi
47+
48+
VERSION="${TAG#v}"
49+
50+
if [ -z "$VERSION" ]; then
51+
echo "ERROR: Tag version is empty (got: $TAG)"
52+
exit 1
53+
fi
54+
55+
JSR_VERSION="$(jq -r '.version // empty' jsr.json)"
56+
PKG_VERSION="$(jq -r '.version // empty' package.json)"
57+
58+
if [ -z "$JSR_VERSION" ] || [ -z "$PKG_VERSION" ]; then
59+
echo "ERROR: Missing version in jsr.json or package.json"
60+
exit 1
61+
fi
62+
63+
if [ "$JSR_VERSION" != "$PKG_VERSION" ]; then
64+
echo "ERROR: Version mismatch!"
65+
echo " jsr.json : $JSR_VERSION"
66+
echo " package.json : $PKG_VERSION"
67+
exit 1
68+
fi
69+
70+
if [ "$JSR_VERSION" != "$VERSION" ]; then
71+
echo "ERROR: Tag does not match versions!"
72+
echo " tag : $TAG"
73+
echo " jsr.json : $JSR_VERSION"
74+
echo " package.json : $PKG_VERSION"
75+
exit 1
76+
fi
77+
78+
echo "is_tag_push=true" >> "$GITHUB_OUTPUT"
79+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
80+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
81+
else
82+
if [ ! -f "jsr.json" ]; then
83+
echo "ERROR: jsr.json not found"
84+
exit 1
85+
fi
86+
87+
if [ ! -f "package.json" ]; then
88+
echo "ERROR: package.json not found"
89+
exit 1
90+
fi
91+
92+
JSR_VERSION="$(jq -r '.version // empty' jsr.json)"
93+
PKG_VERSION="$(jq -r '.version // empty' package.json)"
94+
95+
if [ -z "$JSR_VERSION" ] || [ -z "$PKG_VERSION" ]; then
96+
echo "ERROR: Missing version in jsr.json or package.json"
97+
exit 1
98+
fi
99+
100+
if [ "$JSR_VERSION" != "$PKG_VERSION" ]; then
101+
echo "ERROR: Version mismatch!"
102+
echo " jsr.json : $JSR_VERSION"
103+
echo " package.json : $PKG_VERSION"
104+
exit 1
105+
fi
106+
107+
echo "is_tag_push=false" >> "$GITHUB_OUTPUT"
108+
echo "tag=v$JSR_VERSION" >> "$GITHUB_OUTPUT"
109+
echo "version=$JSR_VERSION" >> "$GITHUB_OUTPUT"
65110
fi
66111
67-
echo "version=$JSR_VERSION" >> "$GITHUB_OUTPUT"
68-
echo "tag=v$JSR_VERSION" >> "$GITHUB_OUTPUT"
69-
70112
- name: Check if tag exists
71113
id: exists
114+
if: steps.meta.outputs.is_tag_push == 'false'
72115
shell: bash
73116
run: |
74117
set -euo pipefail
75-
TAG="${{ steps.ver.outputs.tag }}"
118+
TAG="${{ steps.meta.outputs.tag }}"
76119
git fetch --tags
77120
78121
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
@@ -85,37 +128,41 @@ jobs:
85128
id: out
86129
shell: bash
87130
env:
88-
TAG: ${{ steps.ver.outputs.tag }}
89-
VERSION: ${{ steps.ver.outputs.version }}
131+
IS_TAG_PUSH: ${{ steps.meta.outputs.is_tag_push }}
132+
TAG: ${{ steps.meta.outputs.tag }}
133+
VERSION: ${{ steps.meta.outputs.version }}
90134
EXISTS: ${{ steps.exists.outputs.exists }}
91135
run: |
92136
set -euo pipefail
93137
94-
if [ "$EXISTS" = "false" ]; then
95-
CREATED="true"
138+
if [ "$IS_TAG_PUSH" = "true" ]; then
139+
RUN="true"
140+
CREATE_TAG="false"
96141
else
97-
CREATED="false"
142+
if [ "${EXISTS:-false}" = "false" ]; then
143+
RUN="true"
144+
CREATE_TAG="true"
145+
else
146+
RUN="false"
147+
CREATE_TAG="false"
148+
fi
98149
fi
99150
100151
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
101152
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
102-
echo "created=$CREATED" >> "$GITHUB_OUTPUT"
153+
echo "run=$RUN" >> "$GITHUB_OUTPUT"
154+
echo "create_tag=$CREATE_TAG" >> "$GITHUB_OUTPUT"
103155
104156
ci:
105-
if: github.repository == 'kasperrt/wiretyped' && needs.detect.outputs.created == 'true'
157+
if: github.repository == 'kasperrt/wiretyped' && needs.detect.outputs.run == 'true'
106158
needs: [detect]
107159
uses: ./.github/workflows/ci.yml
108160

109161
tag:
110-
if: github.repository == 'kasperrt/wiretyped' && needs.detect.outputs.created == 'true'
162+
if: github.repository == 'kasperrt/wiretyped' && needs.detect.outputs.run == 'true' && needs.ci.result == 'success'
111163
needs: [detect, ci]
112164
runs-on: ubuntu-latest
113165

114-
outputs:
115-
tag: ${{ steps.out.outputs.tag }}
116-
version: ${{ steps.out.outputs.version }}
117-
created: ${{ steps.out.outputs.created }}
118-
119166
steps:
120167
- name: Checkout
121168
uses: actions/checkout@v4
@@ -137,7 +184,7 @@ jobs:
137184
fi
138185
139186
- name: Create and push tag
140-
if: steps.exists.outputs.exists == 'false'
187+
if: needs.detect.outputs.create_tag == 'true' && steps.exists.outputs.exists == 'false'
141188
shell: bash
142189
run: |
143190
set -euo pipefail
@@ -149,29 +196,9 @@ jobs:
149196
git tag -a "$TAG" -m "Release $TAG"
150197
git push origin "$TAG"
151198
152-
- name: Export job outputs
153-
id: out
154-
shell: bash
155-
env:
156-
TAG: ${{ needs.detect.outputs.tag }}
157-
VERSION: ${{ needs.detect.outputs.version }}
158-
EXISTS: ${{ steps.exists.outputs.exists }}
159-
run: |
160-
set -euo pipefail
161-
162-
if [ "$EXISTS" = "false" ]; then
163-
CREATED="true"
164-
else
165-
CREATED="false"
166-
fi
167-
168-
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
169-
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
170-
echo "created=$CREATED" >> "$GITHUB_OUTPUT"
171-
172199
release:
173-
if: github.repository == 'kasperrt/wiretyped' && needs.tag.outputs.created == 'true'
174-
needs: [tag]
200+
if: github.repository == 'kasperrt/wiretyped' && needs.detect.outputs.run == 'true' && needs.ci.result == 'success' && needs.tag.result == 'success'
201+
needs: [detect, ci, tag]
175202
runs-on: ubuntu-latest
176203

177204
steps:
@@ -184,7 +211,7 @@ jobs:
184211
shell: bash
185212
run: |
186213
set -euo pipefail
187-
TAG="${{ needs.tag.outputs.tag }}"
214+
TAG="${{ needs.detect.outputs.tag }}"
188215
git fetch --tags
189216
git checkout "$TAG"
190217
@@ -209,7 +236,7 @@ jobs:
209236
fi
210237
211238
EXPECTED="v$JSR_VERSION"
212-
TAG="${{ needs.tag.outputs.tag }}"
239+
TAG="${{ needs.detect.outputs.tag }}"
213240
214241
if [ "$TAG" != "$EXPECTED" ]; then
215242
echo "ERROR: Tag does not match versions!"
@@ -237,7 +264,7 @@ jobs:
237264
- name: Determine npm dist-tag
238265
id: npm_tag
239266
env:
240-
VERSION: ${{ needs.tag.outputs.version }}
267+
VERSION: ${{ needs.detect.outputs.version }}
241268
shell: bash
242269
run: |
243270
set -euo pipefail
@@ -272,51 +299,3 @@ jobs:
272299
273300
- name: Publish to JSR
274301
run: pnpx jsr publish
275-
276-
docs:
277-
if: github.repository == 'kasperrt/wiretyped' && needs.tag.outputs.created == 'true'
278-
needs: [tag, release]
279-
runs-on: ubuntu-latest
280-
281-
environment:
282-
name: github-pages
283-
284-
steps:
285-
- name: Checkout
286-
uses: actions/checkout@v4
287-
with:
288-
fetch-depth: 0
289-
290-
- name: Checkout tag
291-
shell: bash
292-
run: |
293-
set -euo pipefail
294-
TAG="${{ needs.tag.outputs.tag }}"
295-
git fetch --tags
296-
git checkout "$TAG"
297-
298-
- uses: pnpm/action-setup@v4
299-
with:
300-
version: 10.26.0
301-
302-
- uses: actions/setup-node@v4
303-
with:
304-
node-version: "20"
305-
cache: "pnpm"
306-
307-
- name: Install dependencies
308-
run: pnpm install --frozen-lockfile
309-
310-
- name: Build docs (GitHub Pages)
311-
env:
312-
DOCS_BASE: "/"
313-
run: pnpm docs:build
314-
315-
- uses: actions/configure-pages@v5
316-
317-
- uses: actions/upload-pages-artifact@v3
318-
with:
319-
path: docs/.vitepress/dist
320-
321-
- id: deployment
322-
uses: actions/deploy-pages@v4

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Releases
22

33
## Contents
4+
- [v0.3.4-alpha.1](#v0-3-4-alpha-1)
45
- [v0.3.4-alpha.0](#v0-3-4-alpha-0)
56
- [v0.3.3](#v0-3-3)
67
- [v0.3.2](#v0-3-2)
@@ -17,6 +18,12 @@
1718
- [v0.1.0](#v0-1-0)
1819
- [v0.0.8](#v0-0-8)
1920

21+
## v0.3.4-alpha.1
22+
23+
- Remove unused shallow flag from isErrorType as it is totally unnecessary.
24+
- Update name on error-classes to be static for better accessibility.
25+
- Internal; Use unwrapErrorType + isErrorType internally rather than larger getters and checkers.
26+
2027
## v0.3.4-alpha.0
2128

2229
- Internal; Handle 205 status-codes more gracefully by defaulting to null returned as body.

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kasperrt/wiretyped",
3-
"version": "0.3.4-alpha.0",
3+
"version": "0.3.4-alpha.1",
44
"exports": {
55
".": "./src/index.ts"
66
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wiretyped",
3-
"version": "0.3.4-alpha.0",
3+
"version": "0.3.4-alpha.1",
44
"description": "Universal fetch-based HTTP client with robust error handling, retries, caching, SSE, and Standard Schema validation.",
55
"type": "module",
66
"keywords": [

src/core/client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { CacheClient } from '../cache/client.js';
22
import { isAbortError } from '../error/abortError.js';
3-
import { getHttpError, HTTPError } from '../error/httpError.js';
4-
import { isErrorType } from '../error/isErrorType.js';
5-
import { isTimeoutError } from '../error/timeoutError.js';
3+
import { HTTPError } from '../error/httpError.js';
4+
import { TimeoutError } from '../error/timeoutError.js';
5+
import { unwrapErrorType } from '../error/unwrapErrorType.js';
66
import { FetchClient } from '../fetch/client.js';
77
import { mergeHeaderOptions } from '../fetch/utils.js';
88
import type {
@@ -749,19 +749,19 @@ export class RequestClient<Schema extends RequestDefinitions> {
749749
attempts: retryAttempts,
750750
timeout: retryTimeout,
751751
errFn: (err) => {
752-
if (isTimeoutError(err)) {
752+
if (unwrapErrorType(TimeoutError, err)) {
753753
return false;
754754
}
755755

756756
if (isAbortError(err)) {
757757
return true;
758758
}
759759

760-
if (isErrorType(TypeError, err)) {
760+
if (unwrapErrorType(TypeError, err)) {
761761
return false;
762762
}
763763

764-
const httpError = getHttpError(err);
764+
const httpError = unwrapErrorType(HTTPError, err);
765765
if (!httpError) {
766766
return false;
767767
}

0 commit comments

Comments
 (0)