Skip to content

enhance: enhancement of the syntex error reporting#4992

Open
MohamedSharfan wants to merge 11 commits intopsf:mainfrom
MohamedSharfan:fix_syntex_error_reporting
Open

enhance: enhancement of the syntex error reporting#4992
MohamedSharfan wants to merge 11 commits intopsf:mainfrom
MohamedSharfan:fix_syntex_error_reporting

Conversation

@MohamedSharfan
Copy link

Description

My fix improves Black's syntex error reporting when parsing fails.

I have made a test file to see the error messege that reports
image

currently when Black encounters invalid python syntex, it reports something like this
image

The changes i have changes to enhance the error message reporting

  1. Reporting by lines and column so maintainer can easily find the error
  2. Displaying the error line and using caret(^) pointing to show exactly where the error is
image

fixes #4820

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

Copilot AI review requested due to automatic review settings February 15, 2026 09:48
Copy link
Contributor

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 PR attempts to enhance Black's syntax error reporting by displaying line numbers, column positions, and using a caret (^) to point to the exact location of syntax errors. The goal is to improve user experience when Black encounters invalid Python syntax, making it easier for developers to identify and fix syntax errors.

Changes:

  • Added exception handling for InvalidInput in the _format_str_once function
  • Implemented line/column extraction from error messages
  • Added error display with caret positioning to indicate error location

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cobaltt7
Copy link
Collaborator

The message should be changed here, inside lib2to3_parse:

f"Cannot parse{tv_str}: {lineno}:{column}: {faulty_line}"

Also, Copilot's suggestions are correct; please review them.

@MohamedSharfan
Copy link
Author

The message should be changed here, inside lib2to3_parse:

f"Cannot parse{tv_str}: {lineno}:{column}: {faulty_line}"

Also, Copilot's suggestions are correct; please review them.

ok sure i will review them and commit again

@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

diff-shades results comparing this PR (f4666ba) to main (6b1392f):

--preview style: no changes

--stable style: no changes


What is this? | Workflow run | diff-shades documentation

f"Cannot parse{tv_str}: {lineno}:{column}: {faulty_line}"
caret_line = "^".rjust(column)
message = (
f"SyntaxError is in line {lineno}, column {column}:\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use wording similar to how it was previously, this message is confusing (and spelled wrong)!

Please also review the test failures.

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.

Improve syntax error reporting for a better user experience

3 participants