Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on adjustment error #4214

Merged
merged 2 commits into from
Apr 9, 2024
Merged

Fix crash on adjustment error #4214

merged 2 commits into from
Apr 9, 2024

Conversation

dorner
Copy link
Collaborator

@dorner dorner commented Mar 22, 2024

There were 4 separate issues here:

  • Invalid name for InventoryError - this has been around for ages.
  • Error message was being appended incorrectly.
  • Error was being raised instead of just added as an error - no calling code is set up to catch errors from this service. Ideally we'd change the flow so it does raise an error and calling code catches it, but that's a bigger change than I have time to do right now.
  • When the error was raised, it wouldn't roll back the transaction - so it would still do the adjustment. Again, this has been around for a long time. :(

The original error seemed to have been caused by issues with re-running events (meaning there was a bad event that got in somehow which indicates that any further actions would all fail).

@dorner dorner requested a review from cielf March 22, 2024 20:18
@cielf
Copy link
Collaborator

cielf commented Mar 22, 2024

@dorner Noting that rubocop is unhappy with this atm.

@cielf
Copy link
Collaborator

cielf commented Mar 22, 2024

(nods) The one weakness in the event sourcing stuff is that if something goes bad, it is going to basically prevent further entry. On the other hand, that does mean we are going to get informed about issues that do occur fairly quickly!

@cielf
Copy link
Collaborator

cielf commented Mar 22, 2024

@dorner We do need to have a discussion on how we troubleshoot/fix things if we do get an error like this -- right now we have a "Beer Truck Problem".

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I'm good with this going in once the rubucop stuff is addressed, in the spirit of "it's better than what was there before."

Comment on lines 31 to 33
rescue Errors::InsufficientAllotment, InventoryError => e
@adjustment.errors.add(:base, e.message)
raise ActiveRecord::Rollback
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question just out of curiosity. in the PR you write

When the error was raised, it wouldn't roll back the transaction - so it would still do the adjustment. Again, this has been around for a long time. :(

Raising any error vs an ActiveRecord::Rollback wouldn't affect rollbacks happening? Like regardless of what error is raised the rollback should happen, right?

I'm just curious if the changes do address that issue, or if that is not longer an issue, cause I don't really see why either version would have an issue with rolling back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that the error was being caught, and a value was added to the errors of the record. But we then just raised the error again, and at that point (I think?) it was already outside of the transaction, so a rollback didn't happen. I went back and forth a lot with this PR - maybe the issue with the rollback was in one of the intermediate states.

@dorner
Copy link
Collaborator Author

dorner commented Apr 5, 2024

Pushed lint fix.

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but holding off on the merge until the release for April 7 is done.

@cielf cielf merged commit ca9cb95 into main Apr 9, 2024
20 checks passed
@cielf cielf deleted the fix-insufficient-allotment-crash branch April 9, 2024 14:53
Copy link
Contributor

@dorner: Your PR Fix crash on adjustment error is part of today's Human Essentials production release: 2024.04.14.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants