Skip to content

Commit

Permalink
Better logging for error updating snapshots (#1804)
Browse files Browse the repository at this point in the history
* Better logging for weird issue

* Adjust the test to match the new error messages

* Also report errors to honeybadger where we're more likely to see them

* Rubocop fix

---------

Co-authored-by: Bess Sadler <[email protected]>
  • Loading branch information
hectorcorrea and bess authored May 6, 2024
1 parent c3c854a commit e35dd92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Metrics/BlockLength:
Max: 40 # default: 25

Metrics/ClassLength:
Exclude: []
Exclude:
- app/controllers/works_wizard_controller.rb
Max: 150 # default: 100

Metrics/CyclomaticComplexity:
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/works_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ def file_uploaded
else
redirect_to(work_review_path)
end
rescue StandardError => active_storage_error
Rails.logger.error("Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}")
flash[:notice] = "Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}. Please contact [email protected] for assistance."
rescue => ex
# Notice that we log the URL (rather than @work.doi) because sometimes we are getting a nil @work.
# The URL will include the ID and might help us troubleshoot the issue further if it happens again.
# See https://github.com/pulibrary/pdc_describe/issues/1801
error_message = "Failed to update work snapshot, URL: #{request.url}: #{ex}"
Rails.logger.error(error_message)
Honeybadger.notify(error_message)
flash[:notice] = "Failed to update work snapshot, work: #{@work&.doi}: #{ex}. Please contact [email protected] for assistance."

redirect_to work_file_upload_path(@work)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/works_wizard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@
# TODO: - how do we tell the user there was an error now that this in not in the page context?
# This error that is happening seems to be just a random error so it is ok that we still capture that
expect(response).to redirect_to(work_file_upload_path(work))
expect(controller.flash[:notice].start_with?("Failed to attach the file uploads for the work #{work.doi}")).to be true
expect(Rails.logger).to have_received(:error).with(/Failed to attach the file uploads for the work #{work.doi}/)
expect(controller.flash[:notice].start_with?("Failed to update work snapshot, work: #{work.doi}")).to be true
expect(Rails.logger).to have_received(:error).with(/Failed to update work snapshot, URL: http\:\/\/test.host\/works\/#{work.id}\/file-upload/)
end
end
end
Expand Down

0 comments on commit e35dd92

Please sign in to comment.