Skip to content

Commit 5ba7980

Browse files
committed
feat(pino-serializer): add serializer and hooks for ThatError integration
1 parent 9cb912a commit 5ba7980

4 files changed

Lines changed: 62 additions & 28 deletions

File tree

.github/workflows/bump-publish.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
package:
1717
description: 'Package names (comma separated) or "all"'
1818
required: false
19-
default: 'core'
19+
default: 'core;pino-serializer'
2020
type: string
2121
publish:
2222
description: 'Publish destination'
@@ -58,7 +58,7 @@ jobs:
5858
run: |
5959
set -euo pipefail
6060
BUMP_TYPE="${{ github.event.inputs.bump }}"
61-
61+
6262
if [ "$BUMP_TYPE" = "none" ]; then
6363
NEW_VER=$(jq -r .version package.json)
6464
echo "Skipping version bump. Current: $NEW_VER"
@@ -68,7 +68,7 @@ jobs:
6868
NEW_VER=$(jq -r .version package.json)
6969
echo "Bumped to new version: $NEW_VER"
7070
fi
71-
71+
7272
echo "BUMP_TYPE=$BUMP_TYPE" >> $GITHUB_ENV
7373
echo "NEW_VERSION=$NEW_VER" >> $GITHUB_ENV
7474
@@ -90,7 +90,7 @@ jobs:
9090
set -euo pipefail
9191
git config user.name "github-actions[bot]"
9292
git config user.email "github-actions[bot]@users.noreply.github.com"
93-
93+
9494
if git status --porcelain | grep -q . ; then
9595
BRANCH_NAME="bump-version/${NEW_VERSION}"
9696
git checkout -B "$BRANCH_NAME"
@@ -106,16 +106,16 @@ jobs:
106106
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107107
run: |
108108
set -euo pipefail
109-
109+
110110
# Create Pull Request using GitHub CLI
111111
PR_URL=$(gh pr create \
112112
--title "chore(release): v${NEW_VERSION}" \
113113
--body "Automated version bump to ${NEW_VERSION}" \
114114
--base "main" \
115115
--head "${PUSHED_BRANCH}")
116-
116+
117117
echo "Created PR: $PR_URL"
118-
118+
119119
# Auto-merge if requested
120120
if [ "${{ github.event.inputs.auto_merge }}" = "true" ]; then
121121
# --auto: waits for status checks to pass before merging
@@ -132,14 +132,14 @@ jobs:
132132
run: |
133133
set -euo pipefail
134134
PUBLISH_TARGET="${{ github.event.inputs.publish }}"
135-
135+
136136
# Initialize .npmrc
137137
: > ~/.npmrc
138-
138+
139139
if [[ "$PUBLISH_TARGET" == "both" || "$PUBLISH_TARGET" == "github" ]]; then
140140
printf "//npm.pkg.github.com/:_authToken=%s\n" "${GH_PACKAGES_PAT}" >> ~/.npmrc
141141
fi
142-
142+
143143
if [[ "$PUBLISH_TARGET" == "both" || "$PUBLISH_TARGET" == "npmjs" ]]; then
144144
printf "//registry.npmjs.org/:_authToken=%s\n" "${NPM_TOKEN}" >> ~/.npmrc
145145
fi
@@ -149,22 +149,22 @@ jobs:
149149
run: |
150150
# Continue on error to attempt publishing all selected packages
151151
set -u -o pipefail
152-
152+
153153
PKG_INPUT="${{ github.event.inputs.package }}"
154154
PUBLISH_TARGET="${{ github.event.inputs.publish }}"
155-
155+
156156
# Define registry URLs
157157
NPMJS_REG="https://registry.npmjs.org/"
158158
GPR_REG="https://npm.pkg.github.com/"
159-
159+
160160
publish_cmd() {
161161
local dir=$1
162162
local reg_url=$2
163163
echo "Publishing $dir to $reg_url..."
164164
# Try bun publish, fallback to npm if it fails
165165
(cd "$dir" && bun publish --registry="$reg_url") || (cd "$dir" && npm publish --registry="$reg_url")
166166
}
167-
167+
168168
# Logic for "all" or specific list
169169
if [ "$PKG_INPUT" = "all" ]; then
170170
TARGETS=$(ls -d packages/*)
@@ -173,7 +173,7 @@ jobs:
173173
TARGETS=""
174174
for i in "${ADDR[@]}"; do TARGETS+=" packages/${i// /}"; done
175175
fi
176-
176+
177177
for D in $TARGETS; do
178178
if [ -d "$D" ] && [ -f "$D/package.json" ]; then
179179
if [[ "$PUBLISH_TARGET" == "both" || "$PUBLISH_TARGET" == "npmjs" ]]; then
@@ -183,4 +183,4 @@ jobs:
183183
publish_cmd "$D" "$GPR_REG"
184184
fi
185185
fi
186-
done
186+
done

bun.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "pino-serializer",
2+
"name": "@thaterror/pino-serializer",
33
"module": "src/index.ts",
44
"type": "module",
55
"private": true,
@@ -8,6 +8,7 @@
88
},
99
"peerDependencies": {
1010
"pino": "^10.1.0",
11-
"typescript": "^5.9.3"
11+
"typescript": "^5.9.3",
12+
"@thaterror/core": "workspace:*"
1213
}
1314
}
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
console.log("Hello via Bun!");
1+
import {
2+
codeOf,
3+
isDefinedError,
4+
payloadOf,
5+
type ThatError,
6+
} from "@thaterror/core";
7+
import type { LoggerOptions, SerializedError } from "pino";
8+
9+
export const thaterrorSerializer = (e: ThatError): SerializedError => {
10+
return {
11+
type: e.constructor.name,
12+
message: e.message,
13+
stack: e.stack ?? "",
14+
raw: e,
15+
name: e.name,
16+
code: codeOf(e),
17+
payload: payloadOf(e),
18+
};
19+
};
20+
21+
export const thaterrorHooks: LoggerOptions["hooks"] = {
22+
logMethod(this, args, method) {
23+
const err = args[0];
24+
if (err && isDefinedError(err)) {
25+
return method.apply(this, [
26+
{ thaterror: err },
27+
args[1],
28+
...args.slice(2),
29+
]);
30+
}
31+
return method.apply(this, args);
32+
},
33+
};

0 commit comments

Comments
 (0)