Skip to content

Commit

Permalink
🔊 Log all Pulumi messages containing 'error:' or 'stderr:' in log_exc…
Browse files Browse the repository at this point in the history
…eption method
  • Loading branch information
jemrobinson committed Aug 8, 2024
1 parent 66a7628 commit 794e9b3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions data_safe_haven/infrastructure/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def destroy(self) -> None:
):
time.sleep(10)
else:
self.log_exception(exc)
msg = "Pulumi resource destruction failed."
raise DataSafeHavenPulumiError(msg) from exc
except DataSafeHavenError as exc:
Expand Down Expand Up @@ -309,9 +310,11 @@ def install_plugins(self, workspace: automation.Workspace) -> None:
raise DataSafeHavenPulumiError(msg) from exc

def log_exception(self, exc: automation.CommandError) -> None:
with suppress(IndexError):
stderr = str(exc).split("\n")[3].replace(" stderr: ", "")
self.log_message(f"Pulumi output: {stderr}")
for error_line in str(exc).split("\n"):
if any(word in error_line for word in ["error:", "stderr:"]):
message = error_line.replace("error:", "").replace("stderr:", "").strip()
if message:
self.log_message(f"Pulumi error: {message}")

def log_message(self, message: str) -> None:
return from_ansi(self.logger, message)
Expand Down Expand Up @@ -383,7 +386,6 @@ def teardown(self, *, force: bool = False) -> None:
self.destroy()
self.cleanup()
except Exception as exc:
self.log_exception(exc)
msg = "Tearing down Pulumi infrastructure failed.."
raise DataSafeHavenPulumiError(msg) from exc

Expand Down

0 comments on commit 794e9b3

Please sign in to comment.