When using typer to parse CLI arguments, I get very verbose and colorful error messages. How can I get a normal Python traceback?
See screenshot for an example traceback (just the first few lines) for illustration of the verbose style:
❯ python scripts/add_priors.py
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/corneliusromer/code/nextclade_data_workflows/sars-cov-2/scripts/add_priors.py:26 in main │
│ │
│ 23 │ import polars as pl │
│ 24 │ │
│ 25 │ priors = ( │
│ ❱ 26 │ │ pl.scan_ndjson(ndjson, infer_schema_length=10000) │
│ 27 │ │ .select( │
│ 28 │ │ │ [ │
│ 29 │ │ │ │ pl.col("nearestNodes"), │
│ │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ json = <module 'json' from │ │
│ │
You can disable it on a one-off basis by setting the environment variable _TYPER_STANDARD_TRACEBACK=1
.
Disabling rich exceptions is possible by passing the kwarg pretty_exceptions_enable=False
when initializing typer
:
import typer
app = typer.Typer(pretty_exceptions_enable=False)
@app.command()
def main():
raise Exception("test")
if __name__ == "__main__":
app()
See the documentation for more options