Skip to content

Commit fee6abe

Browse files
authored
Improve traceback printout (#280)
Now, it prints the last frame of the traceback, in a different color from the message asking to report spin bugs if applicable.
1 parent 1e79f25 commit fee6abe

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

spin/__main__.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import collections
22
import importlib
33
import importlib.util
4-
import inspect
54
import os
65
import pathlib
76
import sys
87
import textwrap
8+
import traceback
99
from typing import Union
1010

1111
import click
@@ -199,17 +199,16 @@ def group(ctx):
199199

200200
try:
201201
group()
202-
except Exception as e:
202+
except Exception:
203203
click.secho(
204-
textwrap.dedent(
205-
f"""\
206-
207-
{type(e).__name__}: {e}
208-
209-
This exception was raised from:
210-
211-
{inspect.trace()[-1].filename}
204+
"\n" + "".join(traceback.format_exception(*sys.exc_info(), limit=-1)),
205+
fg="red",
206+
bold=True,
207+
file=sys.stderr,
208+
)
212209

210+
click.secho(
211+
textwrap.dedent(f"""\
213212
If you suspect this is a bug in `spin`, please file a report at:
214213
215214
https://github.com/scientific-python/spin
@@ -218,9 +217,8 @@ def group(ctx):
218217
219218
spin: {__version__}, package: {proj_name}
220219
221-
Aborting."""
222-
),
223-
fg="red",
220+
Aborting."""),
221+
fg="yellow",
224222
bold=True,
225223
file=sys.stderr,
226224
)

0 commit comments

Comments
 (0)