Skip to content

Commit

Permalink
Merge pull request #139 from flyingcircusio/phil/FC-34644_improve_nix…
Browse files Browse the repository at this point in the history
…_purge_error

[FC-34644] Improve error message for PurgePackage
  • Loading branch information
zagy authored Jan 16, 2024
2 parents 7eac817 + 18055cd commit 896b92f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improve output handling for the `PurgePackage` component. Will not appear like a fatal error in logs anymore when the package has been purged already or is not installed for another reason
10 changes: 8 additions & 2 deletions src/batou_ext/nix.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ class PurgePackage(batou.component.Component):

def verify(self):
try:
self.cmd("nix-env --query {{component.package}}")
self.cmd(f"nix-env --query {self.package}")
raise batou.UpdateNeeded()
except batou.utils.CmdExecutionError as e:
e.report()
if e.stderr.endswith("matches no derivations"):
batou.output.annotate(
f"Could not find package to purge: {self.package}",
yellow=True,
)
else:
e.report()

def update(self):
self.cmd("nix-env --uninstall {{component.package}}")
Expand Down

0 comments on commit 896b92f

Please sign in to comment.