Skip to content

Commit

Permalink
print traceback from cli_handle_exception
Browse files Browse the repository at this point in the history
Instead of only printing the exception info, also print the
traceback.
  • Loading branch information
n8pease committed May 18, 2020
1 parent 7f9e515 commit bc2b202
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions python/lsst/daf/butler/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import click
import io
import os
import traceback
from unittest.mock import MagicMock

from ..core.utils import iterable
Expand Down Expand Up @@ -181,5 +183,9 @@ def cli_handle_exception(func, *args, **kwargs):
return
try:
return func(*args, **kwargs)
except Exception as err:
raise click.ClickException(err)
except Exception:
msg = io.StringIO()
msg.write("An error occurred during command execution:\n")
traceback.print_exc(file=msg)
msg.seek(0)
raise click.ClickException(msg.read())
2 changes: 1 addition & 1 deletion tests/test_cliCmdConfigDump.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_invalidSubset(self):
# test dumping to stdout:
result = runner.invoke(butler.cli, ["config-dump", "here", "--subset", "foo"])
self.assertEqual(result.exit_code, 1)
self.assertEqual(result.output, "Error: 'foo not found in config at here'\n")
self.assertIn("Error: 'foo not found in config at here'", result.output)


if __name__ == "__main__":
Expand Down

0 comments on commit bc2b202

Please sign in to comment.