mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Add possibility to raise errors in source
This commit is contained in:
+4
-1
@@ -10,7 +10,7 @@ import decman
|
||||
import decman.config
|
||||
|
||||
# This is fine since the thing being imported is a class and not a global variable.
|
||||
from decman import UserPackage, File, Directory
|
||||
from decman import UserPackage, File, Directory, UserRaisedError
|
||||
|
||||
# Configuring what packages are installed is easy.
|
||||
# Duplicates are OK, so if you have multiple modules that want to ensure a package is installed,
|
||||
@@ -113,6 +113,9 @@ if socket.gethostname() == "arch-1":
|
||||
# This executes code defined in MyModule which can affect for example what packages are
|
||||
# installed as a part of this module.
|
||||
my_own_mod.enable_my_custom_feature(True)
|
||||
else:
|
||||
# If you want to abort running decman from your config because something is wrong, raise a UserRaisedError
|
||||
raise UserRaisedError("Unknown hostname!")
|
||||
|
||||
decman.modules += [my_own_mod]
|
||||
|
||||
|
||||
@@ -11,6 +11,15 @@ import subprocess
|
||||
import decman.error
|
||||
|
||||
|
||||
class UserRaisedError(Exception):
|
||||
"""
|
||||
Error raised by running source
|
||||
"""
|
||||
|
||||
def __init__(self, message) -> None:
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
def sh(sh_cmd: str,
|
||||
user: typing.Optional[str] = None,
|
||||
env_overrides: typing.Optional[dict[str, str]] = None):
|
||||
|
||||
@@ -79,6 +79,10 @@ def main():
|
||||
for line in traceback.format_exc().splitlines():
|
||||
l.print_debug(line)
|
||||
sys.exit(1)
|
||||
except decman.UserRaisedError as user_error:
|
||||
l.print_error(
|
||||
f"Error encountered while running the source: {user_error}")
|
||||
sys.exit(1)
|
||||
|
||||
# Save even when an error has occurred, since this avoids repeating steps like building pkgs.
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user