fix: always print tracebacks (#28838)
* fix: fallback for always printing tracebacks I don't recall ever hitting "no" to this prompt. It's of no use for me. Also, this makes automated scripts not really automated. * revert: prompting for exceptions Always print full exception
This commit is contained in:
parent
9e8ab92371
commit
9419344c76
1 changed files with 2 additions and 31 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import importlib
|
||||
import json
|
||||
import linecache
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
|
@ -67,37 +66,9 @@ class CliCtxObj:
|
|||
|
||||
|
||||
def handle_exception(cmd, info_name, exc):
|
||||
tb = sys.exc_info()[2]
|
||||
while tb.tb_next:
|
||||
tb = tb.tb_next
|
||||
frame = tb.tb_frame
|
||||
filename = frame.f_code.co_filename
|
||||
lineno = frame.f_lineno
|
||||
click.echo(traceback.format_exc())
|
||||
|
||||
click.secho("\n:: ", nl=False)
|
||||
click.secho(f"{exc}", fg="red", bold=True, nl=False)
|
||||
click.secho(" ::")
|
||||
click.secho("\nContext:", fg="yellow", bold=True)
|
||||
click.secho(f" File '{filename}', line {lineno}\n")
|
||||
context_lines = 5
|
||||
start = max(1, lineno - context_lines)
|
||||
end = lineno + context_lines + 1
|
||||
|
||||
for i in range(start, end):
|
||||
line = linecache.getline(filename, i).rstrip()
|
||||
if i == lineno:
|
||||
click.secho(f"{i:4d}> {line}", fg="red")
|
||||
else:
|
||||
click.echo(f"{i:4d}: {line}")
|
||||
|
||||
show_exception = (not sys.stdout.isatty()) or click.confirm(
|
||||
"\nDo you want to see the full traceback?", default=False
|
||||
)
|
||||
if show_exception:
|
||||
click.secho("\nFull traceback:", fg="red")
|
||||
click.echo(traceback.format_exc())
|
||||
|
||||
click.echo(exc)
|
||||
click.echo(exc)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue