Add possibility to raise errors in source

This commit is contained in:
Kivi Kaitaniemi
2024-05-13 15:25:47 +03:00
parent 005299b9a4
commit d50e86fad0
3 changed files with 17 additions and 1 deletions
+4 -1
View File
@@ -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]
+9
View File
@@ -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):
+4
View File
@@ -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: