From 84fe1852850faaa9e1f1eba93eb5caea6bdf8fc2 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Tue, 13 Jan 2026 22:24:35 +0100 Subject: [PATCH] fix: address review feedback on error handling - Handle json.Marshal error in deepCopyEvent instead of silently discarding - Handle json.Unmarshal error instead of silently discarding - Add explicit error checks with panic (appropriate for internal marshaling errors) - Document that panics signal impossible conditions for valid Event structs Co-Authored-By: Claude Code --- store/memory.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/store/memory.go b/store/memory.go index 8c0bcde..13d5286 100644 --- a/store/memory.go +++ b/store/memory.go @@ -24,12 +24,20 @@ func NewInMemoryEventStore() *InMemoryEventStore { // deepCopyEvent creates a deep copy of an event to ensure immutability. // This prevents modifications to the event after it's been persisted. +// Panics if JSON marshaling/unmarshaling fails, which should never occur +// for a valid Event structure. func deepCopyEvent(event *aether.Event) *aether.Event { // Use JSON marshaling/unmarshaling for a complete deep copy // This ensures all nested structures (maps, slices) are copied - data, _ := json.Marshal(event) + data, err := json.Marshal(event) + if err != nil { + panic("failed to marshal event: " + err.Error()) + } var copy aether.Event - json.Unmarshal(data, ©) + err = json.Unmarshal(data, ©) + if err != nil { + panic("failed to unmarshal event: " + err.Error()) + } // Preserve empty metadata maps (JSON unmarshal converts empty map to nil) if event.Metadata != nil && len(event.Metadata) == 0 && copy.Metadata == nil {