Skip to content

v4.10.0

Choose a tag to compare

@BrianPugh BrianPugh released this 14 Mar 14:09

Features

  • New App.error_formatter field to control out CycloptsError are displayed. The formatter receives a CycloptsError and returns any rich-printable object, replacing the default CycloptsPanel. Can be set at app creation or passed as a runtime override to parse_args / __call__ / run_async. by @BrianPugh in #771

    By default (without error_formatter), errors are displayed in a Rich panel:

    $ my-app foo
    ╭─ Error ─────────────────────────────────────────────────╮
    │ Invalid value "foo" for "VALUE": unable to convert      │
    │ "foo" into int.                                         │
    ╰─────────────────────────────────────────────────────────╯
    

    With a custom formatter, you can simplify or restyle the output:

    from cyclopts import App, CycloptsError
    
    def my_error_formatter(e: CycloptsError):
        return f"[bold red]error:[/bold red] {e}"
    
    app = App(error_formatter=my_error_formatter)
    
    @app.default
    def main(value: int):
        pass
    
    app()
    $ my-app foo
    error: Invalid value "foo" for "VALUE": unable to convert "foo" into int.

Full Changelog: v4.9.0...v4.10.0