Skip to content

Commit 18ba245

Browse files
committed
feat: fix isSerialized
1 parent 857aa6d commit 18ba245

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,14 @@ export class Error0 extends Error {
859859
}
860860

861861
static isSerialized(error: unknown): error is Record<string, unknown> {
862-
return !this.is(error) && typeof error === 'object' && error !== null && 'name' in error && error.name === 'Error0'
862+
return (
863+
!this.is(error) &&
864+
!(error instanceof Error) &&
865+
typeof error === 'object' &&
866+
error !== null &&
867+
'message' in error &&
868+
typeof error.message === 'string'
869+
)
863870
}
864871

865872
static from<TThis extends typeof Error0>(this: TThis, error: unknown): InstanceType<TThis>
@@ -1194,9 +1201,7 @@ export class Error0 extends Error {
11941201
console.error('Error0: failed to serialize message', error0)
11951202
serializedMessage = error0.message
11961203
}
1197-
const json: Record<string, unknown> = {
1198-
name: error0.name,
1199-
}
1204+
const json: Record<string, unknown> = {}
12001205
if (serializedMessage !== undefined) {
12011206
json.message = serializedMessage
12021207
}

src/plugins/tags.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('tagsPlugin', () => {
3838
it('filters tags not in the allow-list when strict is true', () => {
3939
const AppError = Error0.use(tagsPlugin({ tags: [...tags], strict: true }))
4040
const recreated = AppError.from({
41-
name: 'Error0',
4241
message: 'test',
4342
tags: ['db', 'invalid', 123],
4443
})
@@ -48,7 +47,6 @@ describe('tagsPlugin', () => {
4847
it('keeps all string tags when strict is false', () => {
4948
const AppError = Error0.use(tagsPlugin({ tags: [...tags], strict: false }))
5049
const recreated = AppError.from({
51-
name: 'Error0',
5250
message: 'test',
5351
tags: ['db', 'custom', 123],
5452
})

0 commit comments

Comments
 (0)