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 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-01-13 22:24:35 +01:00
parent 69da1d800e
commit 84fe185285

View File

@@ -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, &copy)
err = json.Unmarshal(data, &copy)
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 {