Exceptions¶
docopt2's own exception types: one for a failed parse of argv, one for a malformed usage. See the Diagnostics guide for what they render.
Misuse of the API itself, an unsupported shell name or a program name with shell metacharacters, raises a
plain ValueError instead.
DocoptExit ¶
DocoptExit(
message: str = "",
*,
diagnostic: Diagnostic | None = None,
collected: list[Pattern] | None = None,
left: list[Pattern] | None = None,
usage: str | None = None,
exit_code: int | None = None,
)
Exit because the user invoked the program with incorrect arguments.
Build the exit.
str(exc) stays plain, while the copy the interpreter auto-prints carries color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The plain-text message, used when no |
''
|
diagnostic
|
Diagnostic | None
|
A rendered |
None
|
collected
|
list[Pattern] | None
|
The elements matched before the parse failed, exposing the partial parse. |
None
|
left
|
list[Pattern] | None
|
The argv elements still unconsumed when the parse failed. |
None
|
usage
|
str | None
|
The usage message appended beneath the error. Defaults to the class attribute. |
None
|
exit_code
|
int | None
|
The process status to exit with. Defaults to the class attribute. |
None
|
Source code in src/docopt2/_errors.py
DocoptLanguageError ¶
Error in the construction of the usage message by the developer.