Skip to content

Commit

Permalink
Merge pull request #116 from amyreese/exception-str
Browse files Browse the repository at this point in the history
Fix index error when exceptions have no str() value
  • Loading branch information
amyreese authored Sep 12, 2022
2 parents bd6bf0c + 93eae72 commit e9d3a70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ufmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def echo_results(
if result.error is not None:
msg = str(result.error)
lines = msg.splitlines()
msg = lines[0]
msg = lines[0] if lines else repr(result.error)
click.secho(f"Error formatting {result.path}: {msg}", fg="yellow", err=True)
error += 1

Expand Down
26 changes: 26 additions & 0 deletions ufmt/tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ def test_echo(self, echo_mock, mol_mock):
echo_mock.reset_mock()
mol_mock.reset_mock()

with self.subTest("upstream exception"):
results = [
Result(f1, changed=False),
Result(f2, error=AssertionError()),
Result(f3, error=Exception("something weird happened")),
]
echo_results(results)

echo_mock.assert_has_calls(
[
call(
f"Error formatting {f2}: AssertionError()",
fg="yellow",
err=True,
),
call(
f"Error formatting {f3}: something weird happened",
fg="yellow",
err=True,
),
]
)
mol_mock.assert_not_called()
echo_mock.reset_mock()
mol_mock.reset_mock()

@patch("ufmt.cli.ufmt_paths")
def test_check(self, ufmt_mock):
with self.subTest("no paths given"):
Expand Down

0 comments on commit e9d3a70

Please sign in to comment.