-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
261 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rich >= 13.5 | ||
MDit == 0.0.0.dev14 | ||
ExceptionMan == 0.0.0.dev14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
class PyShellManError(Exception): | ||
from __future__ import annotations as _annotations | ||
from typing import TYPE_CHECKING as _TYPE_CHECKING | ||
from functools import partial as _partial | ||
|
||
from exceptionman import ReporterException as _ReporterException | ||
import mdit as _mdit | ||
|
||
if _TYPE_CHECKING: | ||
from pyshellman.output import ShellOutput | ||
|
||
|
||
class PyShellManError(_ReporterException): | ||
"""Base class for exceptions in this module.""" | ||
def __init__(self, message: str): | ||
self.message = message | ||
super().__init__(message) | ||
def __init__( | ||
self, | ||
title: str, | ||
intro: str, | ||
output: ShellOutput | ||
): | ||
sphinx_config = {"html_title": "PyShellMan Error Report"} | ||
sphinx_target_config = _mdit.target.sphinx( | ||
renderer=_partial( | ||
_mdit.render.sphinx, | ||
config=_mdit.render.get_sphinx_config(sphinx_config) | ||
) | ||
) | ||
report = _mdit.document( | ||
heading=title, | ||
body={"intro": intro}, | ||
section={"details": _mdit.document(heading="Execution Details", body=output.report())}, | ||
target_configs_md={"sphinx": sphinx_target_config}, | ||
) | ||
super().__init__(report=report) | ||
self.output = output | ||
return | ||
|
||
|
||
class PyShellManExecutionError(PyShellManError): | ||
"""Exception raised for errors in the execution of a command.""" | ||
def __init__(self, command: str): | ||
self.command = command | ||
message = f"Shell command '{command}' could not be executed." | ||
super().__init__(message) | ||
def __init__(self, output: ShellOutput): | ||
super().__init__( | ||
title="Execution Error", | ||
intro=f"Shell command was invalid and could not be executed.", | ||
output=output | ||
) | ||
return | ||
|
||
|
||
class PyShellManNonZeroExitCodeError(PyShellManError): | ||
"""Exception raised for non-zero exit code in the execution of a command.""" | ||
def __init__( | ||
self, | ||
command: str, | ||
code: int, | ||
output: str | bytes | None = None, | ||
error: str | bytes | None = None | ||
): | ||
self.command = command | ||
self.code = code | ||
self.output = output | ||
self.error = error | ||
|
||
error_details = "" | ||
if error: | ||
error_details = f"Error:\n{error}\n{'='*50}\n" | ||
if output: | ||
error_details += f"Output:\n{output}" | ||
message = f"Shell command '{command}' failed with exit code {code} " | ||
if error_details: | ||
message += f"and the following output:\n{error_details}" | ||
else: | ||
message += "and no output." | ||
super().__init__(message) | ||
def __init__(self, output: ShellOutput): | ||
super().__init__( | ||
title="Non-Zero Exit Code Error", | ||
intro=f"Shell command exited with a non-zero code.", | ||
output=output | ||
) | ||
return | ||
|
||
|
||
class PyShellManStderrError(PyShellManError): | ||
"""Exception raised for non-empty stderr in the execution of a command.""" | ||
|
||
def __init__( | ||
self, | ||
command: str, | ||
code: int, | ||
output: str | bytes | None = None, | ||
error: str | bytes | None = None | ||
): | ||
self.command = command | ||
self.code = code | ||
self.output = output | ||
self.error = error | ||
|
||
error_details = f"Error:\n{error}\n{'=' * 50}\n" | ||
if output: | ||
error_details += f"Output:\n{output}" | ||
message = ( | ||
f"Shell command '{command}' failed with exit code {code} " | ||
f"and the following output:\n{error_details}" | ||
def __init__(self, output: ShellOutput): | ||
super().__init__( | ||
title="Non-Empty Stderr Error", | ||
intro=f"Shell command produced output on stderr.", | ||
output=output | ||
) | ||
super().__init__(message) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from typing import Literal | ||
|
||
LogLevel = Literal["debug", "success", "info", "notice", "warning", "error", "critical"] |
Oops, something went wrong.