Skip to content

Exceptions and errors

typer-swissknife defines no exception classes of its own. Errors fall in two groups.

When registering (your code)

Raised when command(...) decorates a function or add_typer(...) runs, so you see them at import time, not when a user runs the CLI.

Exception Raised by When
ValueError command, add_typer an alias is empty or whitespace only
ValueError command, add_typer, render_ascii_art, get_ascii_help_text ascii_name / text / title is empty or whitespace only
ValueError add_typer aliases are given but neither name nor sub_app has a name
ValueError add_typer a class has no @command() methods, or a parameter that cannot be a command parameter (details)
TypeError command command() without an app decorates a function that is not a method
pyfiglet.FontNotFound the same four the font is not a known pyfiglet font
import pytest
import typer

from typer_swissknife import add_typer, command

app = typer.Typer()

with pytest.raises(ValueError, match="Aliases must not be empty"):
    command(app, aliases=("",))(lambda: None)

with pytest.raises(ValueError, match="A name is required to register aliases"):
    add_typer(app, typer.Typer(), aliases=("a",))

When running (your users)

Undeclared options for **kwargs that cannot be parsed raise Click's UsageError, which Typer prints with the usage line and exits with code 2. The messages are listed in Undeclared option syntax.