Skip to content

Fix shorthand syntax error location rendering - #10468

Merged
ashovlin merged 2 commits into
aws:developfrom
Abuhaithem:fix/horthand-syntax-error-location
Jul 21, 2026
Merged

Fix shorthand syntax error location rendering#10468
ashovlin merged 2 commits into
aws:developfrom
Abuhaithem:fix/horthand-syntax-error-location

Conversation

@Abuhaithem

Copy link
Copy Markdown
Contributor

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 annotated
with a caret pointing at the parse failure:

$ aws dynamodb put-item --table-name t --item 'a=b,c==d'

Error parsing parameter '--item': Expected: ',', received: '=' for input:
{self._error_location()}

The f-string conversion in that commit left the final fragment of
ShorthandParseSyntaxError._construct_msg without the f prefix, so the
placeholder inside it was emitted verbatim. This affects every command whose
shorthand value fails to parse (--tags, --item, --attributes,
--environment, ...). The sibling DuplicateKeyInObjectError was converted
correctly and is unaffected.

This PR adds the missing f prefix, restoring the exact pre-regression
message:

Error parsing parameter '--item': Expected: ',', received: '=' for input:
a=b,c==d
      ^

Changes

  • awscli/shorthand.py — move the {self._error_location()} placeholder
    into the f-string fragment (one line).
  • tests/unit/test_shorthand.py — add
    test_error_message_includes_error_location, parametrized over a
    mid-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_parsing only asserts the exception type, which
    is 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 — changelog
    entry.

Testing

Per CONTRIBUTING.md, the bug fix includes tests:

  • tests/unit/test_shorthand.py: 117 passed (includes the 3 new regression
    cases)
  • tests/unit/test_argprocess.py: 65 passed (shorthand error surfacing
    through ParamError)
  • Verified end-to-end through bin/aws that the caret diagnostic is
    restored (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.

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.
Comment thread .changes/next-release/bugfix-shorthand-error-location.json Outdated

@ashovlin ashovlin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one comment on the changelog entry, the actual change looks good.

Address review feedback: next-release changelog files must be a single
JSON object, not an array, to satisfy test_next_release_json_is_well_formed.
@Abuhaithem
Abuhaithem requested a review from ashovlin July 21, 2026 06:44
@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.64%. Comparing base (70d3b38) to head (8acd193).
⚠️ Report is 111 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #10468      +/-   ##
===========================================
+ Coverage    93.42%   93.64%   +0.21%     
===========================================
  Files          211      212       +1     
  Lines        17312    17362      +50     
===========================================
+ Hits         16174    16258      +84     
+ Misses        1138     1104      -34     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ashovlin
ashovlin merged commit fbf92fa into aws:develop Jul 21, 2026
50 of 51 checks passed
aws-sdk-python-automation added a commit that referenced this pull request Jul 21, 2026
* release-1.45.53:
  Bumping version to 1.45.53
  Update changelog based on model updates
  Fix quoting in create-invalidation-for-distribution-tenant example (#10470)
  Fix shorthand syntax error location rendering (#10468)
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.

BUG: Shorthand syntax error messages print literal {self._error_location()} instead of the error location

3 participants