Skip to content

fix: handle ValueError in is_debug_mode function#17

Merged
bybatkhuu merged 1 commit intomainfrom
dev
Feb 27, 2026
Merged

fix: handle ValueError in is_debug_mode function#17
bybatkhuu merged 1 commit intomainfrom
dev

Conversation

@bybatkhuu
Copy link
Owner

This pull request introduces a minor improvement to the is_debug_mode() function by making its handling of the DEBUG environment variable more robust. Specifically, it now gracefully ignores any ValueError that may be raised when checking if DEBUG is truthy.

Error handling enhancement:

  • Added a try/except ValueError block around the logic that checks if the DEBUG environment variable is truthy, preventing potential crashes if the value cannot be interpreted. (src/potato_util/_base.py)

@bybatkhuu bybatkhuu self-assigned this Feb 27, 2026
Copilot AI review requested due to automatic review settings February 27, 2026 11:33
@bybatkhuu bybatkhuu merged commit 8b916a5 into main Feb 27, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
pass
logger.debug(f"Invalid DEBUG environment variable value: '{_debug}', treating as False")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants