Skip to content

Improve error handling: stop silently swallowing errors#2

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784470169-error-handling
Open

Improve error handling: stop silently swallowing errors#2
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784470169-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Several handlers in calc.py either ran eval()/float() with no error handling — so invalid or empty input raised exceptions that Tkinter's callback loop silently swallowed to stderr, leaving the UI unresponsive with no feedback — or caught errors without logging them. This PR makes those failures visible: the user sees "Error" and the exception is logged, instead of the app doing nothing or crashing.

Changes:

  • square(), sqrt(), perc(): wrapped the eval() calls in try/except. On failure they now logger.exception(...) and set current_expression = "Error" (matching evaluate()'s behavior) instead of letting an uncaught SyntaxError/NameError escape. Previously e.g. pressing with an empty display crashed the callback (eval("**2")SyntaxError).
  • evaluate(): the except Exception as e: swallowed e without logging. Now logs via logger.exception(...) and also clears total_expression so a bad expression doesn't persist into the next evaluation.
  • memoria() (MS/M+/M-): float(self.current_expression) on non-numeric input (e.g. "Error") raised an uncaught ValueError. Now the value is parsed once up front; on ValueError it logs a warning, shows "Error", and returns instead of crashing.
  • Window icon load in __init__: tk.PhotoImage(file=...) raised an uncaught TclError and aborted startup if the icon was missing. Now caught and logged as a warning so the app still launches.
  • Added a module logger and logging.basicConfig(...) in __main__ so these logs actually surface.

Behavior verified headlessly (xvfb): empty /, M+ on "Error", and evaluating an invalid expression all resolve to "Error" without crashing.

Link to Devin session: https://app.devin.ai/sessions/af3f52009c97490cab8030809ab866ef
Requested by: @martlyma

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@martlyma martlyma self-assigned this Jul 19, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant