Skip to content

Commit

Permalink
Fixed rollback not happening in case of errors (#17)
Browse files Browse the repository at this point in the history
* Fixed rollback not happening in case of errors

* Bump version to 0.1.2
  • Loading branch information
ag14774 authored Oct 15, 2024
1 parent 695c386 commit b92223e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions poetry_monoranger_plugin/monorepo_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,21 @@ def post_execute(self, event: ConsoleTerminateEvent):

installer.whitelist([poetry.package.name])

status = installer.run()

if status != 0 and not command.option("dry-run") and self.pre_add_pyproject is not None:
io.write_line("<error>An error occurred during the installation. Rolling back changes...</error>")
assert isinstance(self.pre_add_pyproject, TOMLDocument)
poetry.file.write(self.pre_add_pyproject)

event.set_exit_code(status)
last_exc = None
status = 0

try:
status = installer.run()
except Exception as e:
last_exc = e
status = 1
finally:
if status != 0 and not command.option("dry-run") and self.pre_add_pyproject is not None:
io.write_line("\n<error>An error occurred during the installation. Rolling back changes...</error>")
assert isinstance(self.pre_add_pyproject, TOMLDocument)
poetry.file.write(self.pre_add_pyproject)

if last_exc is not None:
raise last_exc

event.set_exit_code(status)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-monoranger-plugin"
version = "0.1.1"
version = "0.1.2"
description = "Monoranger is a plugin for Poetry that helps you manage your monorepo, enabling shared lockfiles and virtual environments."
license = "Apache-2.0"
authors = ["Andreas Georgiou <[email protected]>"]
Expand Down

0 comments on commit b92223e

Please sign in to comment.