diff --git a/.rubocop.yml b/.rubocop.yml index d367d02b9..8a7262e20 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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: diff --git a/app/controllers/works_wizard_controller.rb b/app/controllers/works_wizard_controller.rb index 78064ec0b..e7f73a919 100644 --- a/app/controllers/works_wizard_controller.rb +++ b/app/controllers/works_wizard_controller.rb @@ -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 rdss@princeton.edu 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 rdss@princeton.edu for assistance." redirect_to work_file_upload_path(@work) end diff --git a/spec/controllers/works_wizard_controller_spec.rb b/spec/controllers/works_wizard_controller_spec.rb index a8372176c..1e7741f8f 100644 --- a/spec/controllers/works_wizard_controller_spec.rb +++ b/spec/controllers/works_wizard_controller_spec.rb @@ -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