Exit codes and diagnostics¶
Exit codes¶
Code |
Meaning |
Typical cause |
|---|---|---|
|
Success |
Stubs written ( |
|
Stale stubs or failed modules |
|
|
Usage error |
A target that does not exist or is not Python, a module name that cannot be imported
when resolving a target, an import that runs past |
A usage error prints stubpy: error: <message> to stderr:
$ stubpy nonexist
stubpy: error: No module named 'nonexist'
$ echo $?
2
$ stubpy # with a stubpy.toml that contains: mode = "auto"
stubpy: error: .../stubpy.toml: Unknown stubpy option 'mode'
$ echo $?
2
Diagnostics¶
Everything that goes wrong, or is worth noting, while building a stub is recorded as a
Diagnostic instead of being raised. Each has a level, a stage, the symbol
being processed and a message.
Level |
Meaning |
Effect on the run |
|---|---|---|
|
Progress notes, such as how many symbols were found. |
Shown with |
|
Something was approximated; the stub is still usable. A failed import is a warning: the module is stubbed from the source. |
Exit code |
|
The module could not be stubbed, for instance because the source does not parse. A source using syntax newer than the running Python is a WARNING and is skipped instead. |
The module is not written; exit code |
Stages: load, ast_pass, symbol_table, alias, resolve, emit,
import and generator.
result = stubpy.render("broken.py")
for d in result.diagnostics:
print(d)
# [ERROR] (ast_pass) broken.py: Source does not parse on this Python version: SyntaxError: invalid syntax (broken.py, line 3)
Quiet and verbose¶
--quiet prints errors only. --verbose prints every diagnostic, INFO included.
Diagnostics of failed modules are always printed, to stderr.