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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user