Skip to content

Commit

Permalink
form save failure error message improvements (#6679)
Browse files Browse the repository at this point in the history
* form save failure error message improvements

* Removing trailing } which makes for bad grammar

---------

Co-authored-by: Rob Kaufman <rob@notch8.com>
  • Loading branch information
jeremyf and orangewolf authored Feb 8, 2024
1 parent b09be88 commit 453bf83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/controllers/concerns/hyrax/works_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 453bf83

Please sign in to comment.