Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions src/serialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ export class JSONSerializer<T> implements Serializer<T> {
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);
}
}
Expand Down