From 37dafeb8930450e9bad9cf53b418ae67032fdcee Mon Sep 17 00:00:00 2001 From: ncttjz Date: Fri, 17 Jul 2026 11:50:58 +0700 Subject: [PATCH] Fix ShorthandParseSyntaxError message showing literal placeholder instead of caret The _construct_msg method was missing an 'f' prefix on the last string fragment, so '{self._error_location()}' was printed literally instead of showing the caret pointing at the parse failure position. Fixes #10467 --- awscli/shorthand.py | 2 +- tests/unit/test_shorthand.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/awscli/shorthand.py b/awscli/shorthand.py index 18ec091f717a..f8e51168e183 100644 --- a/awscli/shorthand.py +++ b/awscli/shorthand.py @@ -93,7 +93,7 @@ def __init__(self, value, expected, actual, index): def _construct_msg(self): return ( f"Expected: '{self.expected}', received: '{self.actual}' " - f"for input:\n" "{self._error_location()}" + f"for input:\n{self._error_location()}" ) diff --git a/tests/unit/test_shorthand.py b/tests/unit/test_shorthand.py index 8d748d423a0b..8c4f3c49a0be 100644 --- a/tests/unit/test_shorthand.py +++ b/tests/unit/test_shorthand.py @@ -174,6 +174,15 @@ def test_error_parsing(expr): shorthand.ShorthandParser().parse(expr) +def test_error_parsing_message_includes_caret(): + """Error message should include the caret pointing at the parse failure position.""" + with pytest.raises(shorthand.ShorthandParseError) as exc_info: + shorthand.ShorthandParser().parse("a=b,c==d") + msg = str(exc_info.value) + assert "a=b,c==d" in msg + assert "^" in msg + + @pytest.mark.parametrize( "expr", ( # starting with " but unclosed, then repeated \