Skip to content

Better handling for uncaught top-level exceptions#20749

Merged
ilevkivskyi merged 1 commit intopython:masterfrom
ilevkivskyi:better-uncaught-errors
Feb 5, 2026
Merged

Better handling for uncaught top-level exceptions#20749
ilevkivskyi merged 1 commit intopython:masterfrom
ilevkivskyi:better-uncaught-errors

Conversation

@ilevkivskyi
Copy link
Member

Fixes #20633

This has few improvements:

  • Much more robust guarantee that the exit code will be 2 (not 1) on any internal errors.
  • Respect --show-traceback (if possible), and write official error message.
  • Fix formatting of the official error message (there were some extra colons).

This mostly affects bug in incremental mode, where a crash occurs in top-level and/or cache loading, rather that during processing files (where we already have the error catching logic).

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

mypy.errors.report_internal_error(e, None, 0, None, options)
except Exception:
pass
sys.stdout.write(traceback.format_exc())
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be behind an else, i.e. don't print a traceback if report_internal_error does its thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because report_internal_error() already has sys.exit(2). I tested various scenarios locally, they all look good.

@ilevkivskyi ilevkivskyi merged commit b71d355 into python:master Feb 5, 2026
23 checks passed
@ilevkivskyi ilevkivskyi deleted the better-uncaught-errors branch February 5, 2026 20:24
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.

unable to differentiate internal AssertionError from type errors by exit code

2 participants