Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds error handling to the is_debug_mode() function to gracefully handle invalid DEBUG environment variable values. When the DEBUG environment variable contains a value that cannot be interpreted by the is_truthy() validator (e.g., anything other than the recognized values like "true", "false", "yes", "no", "1", "0", etc.), the function now catches the ValueError and treats it as False instead of crashing.
Changes:
- Added try-except block around DEBUG environment variable validation to catch ValueError exceptions when invalid values are provided
- Invalid DEBUG values are now silently ignored and treated as False (not debug mode)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if _debug and is_truthy(_debug): | ||
| _is_debug = True | ||
| except ValueError: | ||
| pass |
There was a problem hiding this comment.
Silently ignoring ValueError when DEBUG contains an invalid value could make configuration issues difficult to debug. Consider logging a warning when an invalid DEBUG value is encountered. The codebase extensively uses logger.debug() in similar scenarios (e.g., in crypto/asymmetric, io modules). A log message like logger.debug(f"Invalid DEBUG environment variable value: '{_debug}', treating as False") would help users understand why their DEBUG setting is being ignored.
| pass | |
| logger.debug(f"Invalid DEBUG environment variable value: '{_debug}', treating as False") |
This pull request introduces a minor improvement to the
is_debug_mode()function by making its handling of theDEBUGenvironment variable more robust. Specifically, it now gracefully ignores anyValueErrorthat may be raised when checking ifDEBUGis truthy.Error handling enhancement:
try/except ValueErrorblock around the logic that checks if theDEBUGenvironment variable is truthy, preventing potential crashes if the value cannot be interpreted. (src/potato_util/_base.py)