Skip to content

Commit ed1bc54

Browse files
authored
Optionally disable Exception catch and locals print (#117)
* add nuclear filter match to finder stamp * add no-catch and no-print-locals flags, disabling catching excveption when running CLI commands and printing lcoals in tracebacks, respectively * fix case args has no attribute no_catch or no_print_locals
1 parent 6e61e92 commit ed1bc54

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

ampel/cli/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import importlib
1111
import importlib.metadata
1212
import os
13-
import sys
1413
import signal
14+
import sys
1515
from random import random
1616

1717
from rich.console import Console
@@ -110,14 +110,26 @@ def main() -> str | int | None:
110110
for k, v in vars(args).items():
111111
print(f" {k}: {v}")
112112

113+
if ('-no-print-locals' in unknown_args) or (hasattr(args, "no_print_locals") and args.no_print_locals):
114+
show_locals = False
115+
else:
116+
show_locals = True
117+
118+
if ('-no-catch' in unknown_args) or (hasattr(args, "no_catch") and args.no_catch):
119+
raise_exc = True
120+
else:
121+
raise_exc = False
122+
113123
console = Console(force_terminal=True, color_system="truecolor")
114124
try:
115125
cli_op.run(vars(args), unknown_args, sub_op)
116126
except KeyboardInterrupt:
117127
console.print("\n[red bold]Interrupted (Ctrl-C)[/]\n")
118128
return 130 # conventional exit code for SIGINT
119129
except BaseException:
120-
console.print_exception(show_locals=True)
130+
if raise_exc:
131+
raise
132+
console.print_exception(show_locals=show_locals)
121133
return 1
122134

123135
return 0

0 commit comments

Comments
 (0)