- Moved all hookify configuration files from `.claude/` to `.claude/hooks/` subdirectory for better organization - Added four new blocking hooks to prevent common error handling anti-patterns: - `block-broad-exception-handler`: Prevents catching generic `Exception` with only logging - `block-datetime-now-fallback`: Blocks returning `datetime.now()` as fallback on parse failures to prevent data corruption - `block-default
1.3 KiB
1.3 KiB
name, enabled, event, pattern, action
| name | enabled | event | pattern | action |
|---|---|---|---|---|
| block-datetime-now-fallback | true | file | return\s+datetime.now\s*( | block |
BLOCKED: datetime.now() fallback detected
Returning datetime.now() as a fallback on parse failures causes data corruption.
Why this is dangerous:
- Silent data corruption - timestamps become incorrect without any error signal
- Debugging nightmare - no way to trace back to the original parse failure
- Data integrity loss - downstream consumers receive fabricated timestamps
What to do instead:
- Return
Noneand let callers handle missing timestamps explicitly - Raise a typed error (e.g.,
DateParseError) so failures are visible - Use
Result[datetime, ParseError]pattern for explicit error handling
Examples from swallowed.md:
_parse_google_datetimereturnsdatetime.now(UTC)onValueErrorparse_outlook_datetimereturnsdatetime.now(UTC)onValueError
Resolution pattern:
# BAD: Silent data corruption
except ValueError:
logger.warning("Failed to parse: %s", dt_str)
return datetime.now(UTC) # Data corruption!
# GOOD: Explicit failure
except ValueError as e:
raise DateParseError(f"Invalid datetime: {dt_str}") from e
# GOOD: Optional return
except ValueError:
logger.warning("Failed to parse: %s", dt_str)
return None # Caller handles missing timestamp