Skip to content

Commit

Permalink
Raise exceptions when updates fail
Browse files Browse the repository at this point in the history
In 000fbee we fixed a data issue which was causing two artefacts in
publisher's database to fail to update.

There was effectively no visibility of this situation from the
developers' perspective - only the user saw the error. We didn't get an
error in sentry, a log message in logit, or even a 500 in the metrics.

The [update](https://www.mongodb.com/docs/mongoid/master/api/Mongoid/Persistable/Updatable.html#update-instance_method)
method in mongoid returns false if the record can't be updated because
it's not valid. We weren't checking the result and logging anything, so
the failure was effectively silent.

Switching to [update!](https://www.mongodb.com/docs/mongoid/master/api/Mongoid/Persistable/Updatable.html#update!-instance_method)
will raise Errors::Validations if the record being updated is not valid.
This will result in the user seeing a 500 / Something went wrong error
page, instead of an validation-style message they can't do anything
about. It will also mean we get an error in Sentry, and in logit, and
there will be a 500 in our metrics.

Alternatively we could check the return value of `update` and log a
warning, but I think this situation is genuinely an error, and it's
better to raise.
  • Loading branch information
richardTowers committed May 3, 2024
1 parent 23ea321 commit d254e1b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/artefact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def latest_edition_id
end

def update_from_edition(edition)
update(
update!(
state: state_from_edition(edition),
description: edition.overview,
public_timestamp: edition.public_updated_at,
Expand Down

0 comments on commit d254e1b

Please sign in to comment.