Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form save failure error message improvements #6679

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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