From 14f7a469f19c5f17ba07b003c0e15e73c1a75ddc Mon Sep 17 00:00:00 2001 From: Dima Z Date: Mon, 9 Feb 2026 18:44:34 -0800 Subject: [PATCH 1/2] Add JSONSerializer string check --- src/serialization.spec.ts | 6 ++++++ src/serialization.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/serialization.spec.ts b/src/serialization.spec.ts index a878604..fca5f58 100644 --- a/src/serialization.spec.ts +++ b/src/serialization.spec.ts @@ -53,6 +53,12 @@ describe('JSONSerializer', () => { ), ); }); + + it('should throw an error when serialization result is undefined', () => { + expect(() => serializer.serialize(undefined)).toThrow( + new SerializerError('Not JSON serializable'), + ); + }); }); describe('DefaultErrorSerializer', () => { diff --git a/src/serialization.ts b/src/serialization.ts index 1353fed..e5f0f4e 100644 --- a/src/serialization.ts +++ b/src/serialization.ts @@ -64,8 +64,15 @@ export class JSONSerializer implements Serializer { serialize(value: T): string { try { // Assumes the value is already in a JSON serializable format. - return JSON.stringify(value); + const result = JSON.stringify(value); + if (typeof result !== 'string') { + throw new SerializerError('Not JSON serializable'); + } + return result; } catch (err) { + if (err instanceof SerializerError) { + throw err; + } throw new SerializerError('Not JSON serializable', err); } } From d9290cc6e7d67d9bbee336aa239ce52425e29daf Mon Sep 17 00:00:00 2001 From: Dima Z Date: Mon, 9 Feb 2026 18:49:09 -0800 Subject: [PATCH 2/2] Add SerializerError for nonstring --- src/executor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/executor.ts b/src/executor.ts index 54d9386..7787c46 100644 --- a/src/executor.ts +++ b/src/executor.ts @@ -331,6 +331,10 @@ export class IdempotentExecutor { type: 'error', error: errorSerializer.serialize(value), }); + } else if (value === undefined) { + await this.cache.set(cacheKey, { + type: 'value', + }); } else { await this.cache.set(cacheKey, { type: 'value',