From 55773f2302968f4a5e156c84b5430a09186bc6e6 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 4 Jan 2024 13:22:27 -0800 Subject: [PATCH 1/2] form save failure error message improvements --- .../concerns/hyrax/works_controller_behavior.rb | 8 +++++++- .../custom_queries/navigators/parent_work_navigator.rb | 2 +- .../navigators/parent_work_navigator_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/hyrax/works_controller_behavior.rb b/app/controllers/concerns/hyrax/works_controller_behavior.rb index b443a45437..9f48dd75c9 100644 --- a/app/controllers/concerns/hyrax/works_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/works_controller_behavior.rb @@ -227,7 +227,13 @@ def form_err_msg(form) end def transaction_err_msg(result) - result.failure.first + msg = if result.failure[1].respond_to?(:full_messages) + "#{result.failure[1].full_messages.to_sentence} [#{result.failure[0]}]" + else + result.failure[0].to_s + end + Rails.logger.info("Transaction failed: #{msg}\n #{result.trace}") + msg end def presenter diff --git a/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb b/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb index 27e1b99cef..a2e1d117c3 100644 --- a/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb +++ b/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb @@ -33,7 +33,7 @@ def find_parent_work(resource:) if results.count > 1 Hyrax.logger.warn("#{resource.work? ? 'Work' : 'File set'} " \ "#{resource.id} is in #{results.count} works when it " \ - "should be in no more than one.") + "should be in no more than one. Found in #{results.map(&:id).join(', ')}}") end results.first end diff --git a/spec/services/hyrax/custom_queries/navigators/parent_work_navigator_spec.rb b/spec/services/hyrax/custom_queries/navigators/parent_work_navigator_spec.rb index e72a618778..2d7dfc41d9 100644 --- a/spec/services/hyrax/custom_queries/navigators/parent_work_navigator_spec.rb +++ b/spec/services/hyrax/custom_queries/navigators/parent_work_navigator_spec.rb @@ -29,7 +29,7 @@ let(:child_work3) { FactoryBot.valkyrie_create(:hyrax_work, id: 'cw3', title: ['Child Work 3']) } let(:member_ids) { [child_work3.id] } it 'logs warning about more than one parent and returns the first parent work as Valkyrie resources' do - expect(Hyrax.logger).to receive(:warn).with("Work cw3 is in 2 works when it should be in no more than one.") + expect(Hyrax.logger).to receive(:warn).with("Work cw3 is in 2 works when it should be in no more than one. Found in pw1, pw2.") parent = custom_query_service.find_parent_work(resource: child_work3) # There is no guarantee which of the parents will be returned. expect([work.id, parent_work.id]).to include parent.id @@ -47,7 +47,7 @@ let(:fileset3) { FactoryBot.valkyrie_create(:hyrax_file_set, id: 'fs3', title: ['Child File Set 3']) } let(:member_ids) { [fileset3.id] } it 'logs warning about more than one parent and returns the first parent work as Valkyrie resources' do - expect(Hyrax.logger).to receive(:warn).with("File set fs3 is in 2 works when it should be in no more than one.") + expect(Hyrax.logger).to receive(:warn).with("File set fs3 is in 2 works when it should be in no more than one. Found in pw1, pw2.") parent = custom_query_service.find_parent_work(resource: fileset3) # There is no guarantee which of the parents will be returned. expect([work.id, parent_work.id]).to include parent.id From c56c987cc78e44e18340b1dc573f99947e3bb131 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 8 Feb 2024 10:03:49 -0500 Subject: [PATCH 2/2] Removing trailing } which makes for bad grammar --- .../hyrax/custom_queries/navigators/parent_work_navigator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb b/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb index a2e1d117c3..f248c243bf 100644 --- a/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb +++ b/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb @@ -33,7 +33,7 @@ def find_parent_work(resource:) if results.count > 1 Hyrax.logger.warn("#{resource.work? ? 'Work' : 'File set'} " \ "#{resource.id} is in #{results.count} works when it " \ - "should be in no more than one. Found in #{results.map(&:id).join(', ')}}") + "should be in no more than one. Found in #{results.map(&:id).join(', ')}.") end results.first end