[Debug Branch] Log and skip error at object level#98
[Debug Branch] Log and skip error at object level#98kchiranjewee63 wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modifies error handling behavior in the entity object processing logic to log validation errors and skip problematic objects instead of failing the entire operation. The change converts a fail-fast approach to a more resilient processing pattern.
- Changes error handling from returning early on validation failure to logging and continuing
- Adds JSON marshaling to capture complete object details in error logs
- Implements graceful degradation by skipping invalid objects rather than stopping processing
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Log the complete object and skip it instead of returning error | ||
| objectJSON, jsonErr := json.Marshal(object) | ||
| if jsonErr != nil { | ||
| log.Printf("[ERROR] Failed to marshal object for logging: %v. Original error: %s", jsonErr, adapterErr.Message) |
There was a problem hiding this comment.
The error message format is inconsistent - using %v for jsonError but %s for adapterErr.Message. Both should use %v for consistency since they're both error types.
| objectJSON, jsonErr := json.Marshal(object) | ||
| if jsonErr != nil { | ||
| log.Printf("[ERROR] Failed to marshal object for logging: %v. Original error: %s", jsonErr, adapterErr.Message) | ||
| } else { | ||
| log.Printf("[ERROR] Skipping object due to validation error. Entity: %s, Error: %s, Object: %s", | ||
| reverseMapping.Id, adapterErr.Message, string(objectJSON)) | ||
| } |
There was a problem hiding this comment.
Logging the complete object JSON may expose sensitive data in logs. Consider redacting or limiting the logged object content, especially if objects may contain PII or sensitive information.
| objectJSON, jsonErr := json.Marshal(object) | |
| if jsonErr != nil { | |
| log.Printf("[ERROR] Failed to marshal object for logging: %v. Original error: %s", jsonErr, adapterErr.Message) | |
| } else { | |
| log.Printf("[ERROR] Skipping object due to validation error. Entity: %s, Error: %s, Object: %s", | |
| reverseMapping.Id, adapterErr.Message, string(objectJSON)) | |
| } | |
| // Avoid logging full object to prevent leaking sensitive data | |
| log.Printf("[ERROR] Skipping object due to validation error. Entity: %s, Error: %s, ObjectType: %T", | |
| reverseMapping.Id, adapterErr.Message, object) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #98 +/- ##
==========================================
- Coverage 48.70% 48.59% -0.11%
==========================================
Files 24 24
Lines 2655 2669 +14
==========================================
+ Hits 1293 1297 +4
- Misses 1306 1314 +8
- Partials 56 58 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
No description provided.