Skip to content

Y25-467 - Handle invalid byte sequence exception - #6098

Open
StephenHulme wants to merge 9 commits into
developfrom
y25-467-handle-invalid-byte-exception
Open

StephenHulme wants to merge 9 commits into
developfrom
y25-467-handle-invalid-byte-exception

Conversation

@StephenHulme

@StephenHulme StephenHulme commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Closes #5122

Changes proposed in this pull request

  • Tidy up unit tests (the majority of this PR)
  • Rescues CSV::InvalidEncodingError
    • Displays flash message to user
    • Records error log

I could not replicate the same failure mode as in the exception notifications, but have added the suggested error handling which should catch any future occurrences.

Instructions for Reviewers

[All PRs] - Confirm PR template filled
[Feature Branches] - Review code
[Production Merges to main]
    - Check story numbers included
    - Check for debug code
    - Check version

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.24%. Comparing base (22d03eb) to head (f451ce5).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6098      +/-   ##
===========================================
+ Coverage    82.22%   82.24%   +0.01%     
===========================================
  Files         1317     1317              
  Lines        32208    32210       +2     
  Branches      3503     3503              
===========================================
+ Hits         26482    26490       +8     
+ Misses        4920     4912       -8     
- Partials       806      808       +2     
Flag Coverage Δ
javascript 10.68% <ø> (ø)
ruby 83.50% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +129 to 150
context 'when the upload fails due to an Invalid byte sequence error' do
before do
allow(uploader).to receive(:run!).and_raise(CSV::InvalidEncodingError.new(Encoding::UTF_8, 10))
allow(Rails.logger).to receive(:error).and_call_original
post :create, params: { upload: upload_file }
end

it 'logs the invalid encoding error' do
expect(Rails.logger).to have_received(:error).with('Invalid byte sequence in UTF-8 in line 10.')
end

it 'sets an error flash message' do
expect(flash[:error]).to eq(
'The sample manifest contained invalid encoding and could not be uploaded: ' \
'Invalid byte sequence in UTF-8 in line 10.'
)
end

it 'renders the new template' do
expect(response).to render_template(:new)
end
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added unit test 👆

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Y25-467 - [Psd-exceptions] [Sequencescape Production] sample_manifest_upload_with_tag_sequences#create (CSV::MalformedCSVError) "Invalid byte seque...

1 participant