exceptions¶
Custom exception classes.
These vary in use case from “we needed a specific data structure layout in exceptions used for message-passing” to simply “we needed to express an error condition in a way easily told apart from other, truly unexpected errors”.
- exception invoke.exceptions.AmbiguousEnvVar¶
Raised when loading env var config keys has an ambiguous target.
在 1.0 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.AuthFailure(result: Result, prompt: str)¶
An authentication failure, e.g. due to an incorrect
sudopassword.备注
Resultobjects attached to these exceptions typically lack exit code information, since the command was never fully executed - the exception was raised instead.在 1.0 版本加入.
- exception invoke.exceptions.CollectionNotFound(name: str, start: str)¶
-
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.CommandTimedOut(result: Result, timeout: int)¶
Raised when a subprocess did not exit within a desired timeframe.
- exception invoke.exceptions.Exit(message: str | None = None, code: int | None = None)¶
Simple custom stand-in for SystemExit.
Replaces scattered sys.exit calls, improves testability, allows one to catch an exit request without intercepting real SystemExits (typically an unfriendly thing to do, as most users calling
sys.exitrather expect it to truly exit.)Defaults to a non-printing, exit-0 friendly termination behavior if the exception is uncaught.
If
code(an int) given, that code is used to exit.If
message(a string) given, it is printed to standard error, and the program exits with code1by default (unless overridden by also givingcodeexplicitly.)在 1.0 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.Failure(result: Result, reason: WatcherError | None = None)¶
Exception subclass representing failure of a command execution.
“Failure” may mean the command executed and the shell indicated an unusual result (usually, a non-zero exit code), or it may mean something else, like a
sudocommand which was aborted when the supplied password failed authentication.Two attributes allow introspection to determine the nature of the problem:
result: aResultinstance with info about the command being executed and, if it ran to completion, how it exited.reason: a wrapped exception instance if applicable (e.g. aStreamWatcherraisedWatcherError) orNoneotherwise, in which case, it’s probably aFailuresubclass indicating its own specific nature, such asUnexpectedExitorCommandTimedOut.
This class is only rarely raised by itself; most of the time
Runner.run(or a wrapper of same, such asContext.sudo) will raise a specific subclass likeUnexpectedExitorAuthFailure.在 1.0 版本加入.
- __init__(result: Result, reason: WatcherError | None = None) None¶
- __weakref__¶
list of weak references to the object
- streams_for_display() Tuple[str, str]¶
Return stdout/err streams as necessary for error display.
Subject to the following rules:
If a given stream was not hidden during execution, a placeholder is used instead, to avoid printing it twice.
Only the last 10 lines of stream text is included.
PTY-driven execution will lack stderr, and a specific message to this effect is returned instead of a stderr dump.
- 返回:
Two-tuple of stdout, stderr strings.
在 1.3 版本加入.
- exception invoke.exceptions.ParseError(msg: str, context: ParserContext | None = None)¶
An error arising from the parsing of command-line flags/arguments.
Ambiguous input, invalid task names, invalid flags, etc.
在 1.0 版本加入.
- __init__(msg: str, context: ParserContext | None = None) None¶
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.PlatformError¶
Raised when an illegal operation occurs for the current platform.
E.g. Windows users trying to use functionality requiring the
ptymodule.Typically used to present a clearer error message to the user.
在 1.0 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.ResponseNotAccepted¶
A responder/watcher class noticed a ‘bad’ response to its submission.
Mostly used by
FailingResponderand subclasses, e.g. “oh dear I autosubmitted a sudo password and it was incorrect.”在 1.0 版本加入.
- exception invoke.exceptions.SubprocessPipeError¶
Some problem was encountered handling subprocess pipes (stdout/err/in).
Typically only for corner cases; most of the time, errors in this area are raised by the interpreter or the operating system, and end up wrapped in a
ThreadException.在 1.3 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.ThreadException(exceptions: List[ExceptionWrapper])¶
One or more exceptions were raised within background threads.
The real underlying exceptions are stored in the
exceptionsattribute; see its documentation for data structure details.备注
Threads which did not encounter an exception, do not contribute to this exception object and thus are not present inside
exceptions.在 1.0 版本加入.
- __init__(exceptions: List[ExceptionWrapper]) None¶
- __weakref__¶
list of weak references to the object
- exceptions: Tuple[ExceptionWrapper, ...] = ()¶
A tuple of
ExceptionWrapperscontaining the initial thread constructor kwargs (becausethreading.Threadsubclasses should always be called with kwargs) and the caught exception for that thread as seen bysys.exc_info(so: type, value, traceback).备注
The ordering of this attribute is not well-defined.
备注
Thread kwargs which appear to be very long (e.g. IO buffers) will be truncated when printed, to avoid huge unreadable error display.
- exception invoke.exceptions.UncastableEnvVar¶
Raised on attempted env var loads whose default values are too rich.
E.g. trying to stuff
MY_VAR="foo"into{'my_var': ['uh', 'oh']}doesn’t make any sense until/if we implement some sort of transform option.在 1.0 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.UnexpectedExit(result: Result, reason: WatcherError | None = None)¶
A shell command ran to completion but exited with an unexpected exit code.
Its string representation displays the following:
Command executed;
Exit code;
The last 10 lines of stdout, if it was hidden;
The last 10 lines of stderr, if it was hidden and non-empty (e.g. pty=False; when pty=True, stderr never happens.)
在 1.0 版本加入.
- exception invoke.exceptions.UnknownFileType¶
A config file of an unknown type was specified and cannot be loaded.
在 1.0 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.UnpicklableConfigMember¶
A config file contained module objects, which can’t be pickled/copied.
We raise this more easily catchable exception instead of letting the (unclearly phrased) TypeError bubble out of the pickle module. (However, to avoid our own fragile catching of that error, we head it off by explicitly testing for module members.)
在 1.0.2 版本加入.
- __weakref__¶
list of weak references to the object
- exception invoke.exceptions.WatcherError¶
Generic parent exception class for
StreamWatcher-related errors.Typically, one of these exceptions indicates a
StreamWatchernoticed something anomalous in an output stream, such as an authentication response failure.Runnercatches these and attaches them toFailureexceptions so they can be referenced by intermediate code and/or act as extra info for end users.在 1.0 版本加入.
- __weakref__¶
list of weak references to the object