|
18 | 18 |
|
19 | 19 | # Standard Library |
20 | 20 | import typing |
21 | | -import warnings |
22 | 21 |
|
23 | 22 | # Package Implementation |
24 | 23 | from exec_helpers import proc_enums |
@@ -320,44 +319,75 @@ def __init__( |
320 | 319 | self.exceptions: typing.Dict[typing.Tuple[str, int], Exception] = exceptions |
321 | 320 |
|
322 | 321 |
|
323 | | -class ParallelCallExceptions(ParallelCallExceptionsError): # noqa: N818 |
324 | | - """Exception raised during parallel call as result of exceptions.""" |
| 322 | +ParallelCallExceptions = ParallelCallExceptionsError # noqa: N818 |
325 | 323 |
|
326 | | - __slots__ = () |
| 324 | + |
| 325 | +class StopExecution(Exception): # noqa:N818 |
| 326 | + """Stop execution without waiting for exit code.""" |
327 | 327 |
|
328 | 328 | def __init__( |
329 | 329 | self, |
330 | | - command: str, |
331 | | - exceptions: typing.Dict[typing.Tuple[str, int], Exception], |
332 | | - errors: typing.Dict[typing.Tuple[str, int], exec_result.ExecResult], |
333 | | - results: typing.Dict[typing.Tuple[str, int], exec_result.ExecResult], |
334 | | - expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,), |
335 | | - *, |
336 | | - _message: typing.Optional[str] = None, |
| 330 | + trigger_line: bytes, |
| 331 | + result: exec_result.ExecResult, |
| 332 | + message: str = "StopExecution raised", |
337 | 333 | ) -> None: |
338 | | - """Exception raised during parallel call as result of exceptions. |
| 334 | + self.__trigger_line = trigger_line |
| 335 | + self.__result = result |
| 336 | + super().__init__(message) |
339 | 337 |
|
340 | | - :param command: command |
341 | | - :type command: str |
342 | | - :param exceptions: Exceptions on connections |
343 | | - :type exceptions: typing.Dict[typing.Tuple[str, int], Exception] |
344 | | - :param errors: results with errors |
345 | | - :type errors: typing.Dict[typing.Tuple[str, int], ExecResult] |
346 | | - :param results: all results |
347 | | - :type results: typing.Dict[typing.Tuple[str, int], ExecResult] |
348 | | - :param expected: expected return codes |
349 | | - :type expected: typing.Iterable[typing.Union[int, proc_enums.ExitCodes]] |
350 | | - :param _message: message override |
351 | | - :type _message: typing.Optional[str] |
| 338 | + @property |
| 339 | + def trigger_line(self) -> bytes: |
| 340 | + """Trigger line for exception. |
352 | 341 |
|
353 | | - .. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent |
| 342 | + :return: original line triggered StopExecution as bytes |
| 343 | + :rtype: bytes |
354 | 344 | """ |
355 | | - warnings.warn("ParallelCallExceptions is deprecated and will be dropped soon", DeprecationWarning) |
| 345 | + return self.__trigger_line |
| 346 | + |
| 347 | + @property |
| 348 | + def trigger_string(self) -> str: |
| 349 | + """Decoded trigger line for exception. |
| 350 | +
|
| 351 | + :return: original line triggered StopExecution as str |
| 352 | + :rtype: str |
| 353 | + """ |
| 354 | + return self.__trigger_line.decode("utf-8", errors="backslashreplace") |
| 355 | + |
| 356 | + @property |
| 357 | + def result(self) -> exec_result.ExecResult: |
| 358 | + """Execution result object. |
| 359 | +
|
| 360 | + :return: execution result object |
| 361 | + :rtype: exec_result.ExecResult |
| 362 | + """ |
| 363 | + return self.__result |
| 364 | + |
| 365 | + |
| 366 | +class StopExecutionGraceful(StopExecution): # noqa:N818 |
| 367 | + """Stop execution without raising exception.""" |
| 368 | + |
| 369 | + def __init__( |
| 370 | + self, |
| 371 | + trigger_line: bytes, |
| 372 | + result: exec_result.ExecResult, |
| 373 | + ) -> None: |
356 | 374 | super().__init__( |
357 | | - command=command, |
358 | | - exceptions=exceptions, |
359 | | - errors=errors, |
360 | | - results=results, |
361 | | - expected=expected, |
362 | | - _message=_message, |
| 375 | + trigger_line=trigger_line, |
| 376 | + result=result, |
| 377 | + message="Graceful early stop of execution.", |
| 378 | + ) |
| 379 | + |
| 380 | + |
| 381 | +class StopExecutionError(StopExecution, ExecHelperError): |
| 382 | + """Stop execution and raise exception.""" |
| 383 | + |
| 384 | + def __init__( |
| 385 | + self, |
| 386 | + trigger_line: bytes, |
| 387 | + result: exec_result.ExecResult, |
| 388 | + ) -> None: |
| 389 | + super().__init__( |
| 390 | + trigger_line=trigger_line, |
| 391 | + result=result, |
| 392 | + message="Unexpected command output caused stop of execution.", |
363 | 393 | ) |
0 commit comments