From 9419344c7652deef3602ebf84770f30f3ff5ee08 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 19 Dec 2024 18:16:11 +0530 Subject: [PATCH] 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 --- frappe/utils/bench_helper.py | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/frappe/utils/bench_helper.py b/frappe/utils/bench_helper.py index 51e6d97ee7..4381d3b0cd 100755 --- a/frappe/utils/bench_helper.py +++ b/frappe/utils/bench_helper.py @@ -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():