Fix shorthand syntax error location rendering#10468
Open
Abuhaithem wants to merge 1 commit into
Open
Conversation
The f-string conversion in 9a2e047 left the final fragment of ShorthandParseSyntaxError._construct_msg without an f prefix, so every shorthand syntax error printed the literal text "{self._error_location()}" instead of the input expression with a caret pointing at the parse failure. Add the missing prefix, restoring the pre-regression message, and lock the full message contents (input echo and caret position) with regression tests for both shorthand error types. The existing tests only asserted the exception type, which is why this regressed unnoticed.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10467
Since commit 9a2e047 ("Format base *.py files at top level awscli
directory", August 2024), shorthand syntax errors have printed the literal
text
{self._error_location()}instead of the input expression annotatedwith a caret pointing at the parse failure:
The f-string conversion in that commit left the final fragment of
ShorthandParseSyntaxError._construct_msgwithout thefprefix, so theplaceholder inside it was emitted verbatim. This affects every command whose
shorthand value fails to parse (
--tags,--item,--attributes,--environment, ...). The siblingDuplicateKeyInObjectErrorwas convertedcorrectly and is unaffected.
This PR adds the missing
fprefix, restoring the exact pre-regressionmessage:
Changes
awscli/shorthand.py— move the{self._error_location()}placeholderinto the f-string fragment (one line).
tests/unit/test_shorthand.py— addtest_error_message_includes_error_location, parametrized over amid-string syntax error, an EOF syntax error, and the duplicate-key error.
Each case asserts the complete message, including the caret position. The
pre-existing
test_error_parsingonly asserts the exception type, whichis the coverage gap that allowed this to regress silently; these cases
close it for both shorthand error types.
.changes/next-release/bugfix-shorthand-error-location.json— changelogentry.
Testing
Per CONTRIBUTING.md, the bug fix includes tests:
tests/unit/test_shorthand.py: 117 passed (includes the 3 new regressioncases)
tests/unit/test_argprocess.py: 65 passed (shorthand error surfacingthrough
ParamError)bin/awsthat the caret diagnostic isrestored (no credentials required; parsing fails client-side)
No parsing behavior changes; only the error-message string on an
error-only path is affected. The restored text is identical to the output
of all releases prior to August 2024.
This pull request was generated with the assistance of AI tooling and
reviewed by Abuhaithem, per the repository's Automated Tools contribution
guidelines.