Skip to content

Commit

Permalink
Evade ValueError exception on ShorthandParserError
Browse files Browse the repository at this point in the history
  • Loading branch information
uchida committed Oct 4, 2015
1 parent de2a969 commit 0cc582d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions awscli/shorthand.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, value, expected, actual, index):
super(ShorthandParseError, self).__init__(msg)

def _construct_msg(self):
if '\n' in self.value:
if '\n' in self.value[:self.index]:
# If there's newlines in the expression, we want
# to make sure we're only counting the spaces
# from the last newline:
Expand All @@ -79,8 +79,10 @@ def _construct_msg(self):
"Expected: '%s', received: '%s' for input:\n"
"%s\n"
"%s\n"
) % (self.expected, self.actual, self.value,
' ' * num_spaces + '^')
"%s\n"
) % (self.expected, self.actual, self.value[:self.index],
' ' * num_spaces + '^',
self.value[self.index:])
return msg


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_shorthand.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_error_parsing():
yield (_is_error, "foo={bar}")
yield (_is_error, "foo={bar=bar")
yield (_is_error, "foo=bar,")

yield (_is_error, "foo=bar',\nbar=bar")

def _is_error(expr):
try:
Expand Down

0 comments on commit 0cc582d

Please sign in to comment.