-
Notifications
You must be signed in to change notification settings - Fork 687
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
Handle FileNotFoundError on download of messages #5573
Handle FileNotFoundError on download of messages #5573
Conversation
Thanks for picking this up @DrGFreeman. Don't hesitate to comment if you're looking for feedback even while it's still in draft stage. |
Thanks for the follow-up @eloquence. I was having difficulty setting up the missing file for the functional tests but figured out a way today (ref 995eed0). I'm not yet done with the PR as I also want to check for proper logging of the error. UX feedback would however be welcome when you or someone has time. I added testing steps to the PR. |
As discussed in #4787 (comment), I used a catch-all flash message for now. I'm open for modifications of the message as well as the error message being logged. Thx. |
Kicked the error message around a bit with @creviera and @ninavizz. Currently:
(Also used in other contexts.) Proposed option A replacement:
Proposed option B replacement:
Rationale:
Thoughts @DrGFreeman, others? |
@eloquence, thanks for the feedback.
I would personally go with option A as it refers the user to their admin while hinting at the additional information in the logs. With option B, as a journalist I may not know how to access the system logs and/or think about contacting the admin.
I fully agree. Side note: Instead of creating a new message, I used one that was already in the codebase: securedrop/securedrop/journalist_app/main.py Lines 130 to 132 in 6475ae8
securedrop/securedrop/journalist_app/utils.py Lines 58 to 60 in 44a2e52
securedrop/securedrop/journalist_app/utils.py Lines 157 to 159 in 44a2e52
Maybe we should consider improving these messages as well? I could include this as an additional change in this PR. |
Thanks @DrGFreeman. Yes, I noticed that, and think we should standardize the message where it is used, assuming of course that errors are indeed logged in all those cases. I suggest we wait another day or so, in case other folks want to weigh in before we do that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm: we no longer display a FileNotFoundError with traceback; instead a more user-friendly error is shown on the same page. one improvement would be to keep the checkboxes checked after an error rather than clearing the selection. this will help the user remember which files they tried to download. i think it's fine to create a follow-up issue if this takes too much time, especially since we might want to catch the missing files early on and handle it differently in the future. sounds like we're going to let this pr sit a bit longer to discuss error messaging, which gives you time to address my comment about logging and leaving the checkboxes checked (but again more than happy to open some follow-up issues for this just like i did for the bug found while testing your pr: freedomofpress/securedrop-client#1173)
Forgot to share this lovely test plan: Scenario 1 - Download via "n unread" button on
Scenario 2 - Download via "Download Unread" button on
Scenario 3 - Download via "Download" button on
Scenario 4 - Download via "Download Selected" button on
Scenario 5 - Direct message download from
|
re proposed error message replacement options - couple of suggestions:
|
@creviera, thanks for the feedback! I'll look into updating the error messages per your suggestions over the weekend and see how I can proceed to leave the messages selected in the case where the user used "Download Selected" (test scenario 4). |
581e91f
to
ee18a23
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks great! tests pass and there are clear logs of which files are missing. left one review comment.
os.path.basename(filename) | ||
)) | ||
return zip_file | ||
missing_files = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something but why not raise FileNotFoundError
here directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow logging all the missing files if more than one are missing (see commit message ee18a23)
@creviera & @eloquence, returning on this discussion:
Initially we were to use a single generic message for all these errors. Now that the message is specific to missing files, I did not update the other instances. I could update these other messages in this PR but I'd have to review their context and propose appropriate messages. Or would you prefer to raise a follow-up issue for these other messages? Please advise. |
I think that's the best course of action here, we can revisit that at a later time if warranted. You are a bit behind |
Handle the FileNotFoundError on download of message in the JI where the corresponding file is missing on the filesystem. - Display a flash message to the journalist. - Add a log entry reporting the error. - Redirect to the page from which the download was attempted.
Implement functional tests for the case where a message file is missing in the store. One test for each of the five ways to download a message from the journalist interface. Each test implements the following: -Creates a message from the source interface -Delete the message file from the store -Attempts to download the message from the journalist interface -Check that a flash message is displayed in the journalist interface -Check that the journalist remains on the page from which they attempted to download the message
Check error logging for bulk download via /bulk and single message download via /col/<filesystem_id>/<fn>.
- If more than one file is missing in bulk download, add a log entry for each missing file before returning the FileNotFound exception. - Update unit test to verify logging of multiple missing files. - Improve flashed error message. - Rename tests, fixture and journalist navigation steps to align with changes. - Rename file_ variable to file.
Change the return type to the more generic werkzeug.Response which represents both the return types of flask.redirect (werkzeug.Response) and flask.send_file (flask.Response which is derived from wekrzeuf.Response).
Improve flash message text based on feedback from PR review process.
38b0aa4
to
592410f
Compare
@eloquence & @creviera, here you go, rebased and all tests passing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ran through the test plan again and lgtm
Status
Ready for review.
Description of Changes
Fixes #4787
Changes proposed in this pull request:
Handle the
FileNotFoundError
on download of message in the JI where the corresponding file is missing on the filesystem.Also added functional test for flash message and redirect and tests for logging of the error.
Testing
How should the reviewer test this PR?
Write out any special testing steps here.
Setup
make dev
.docker exec -it securedrop-dev-0 bash
and delete the first message (filename1-something_something-msg.gpg
) from the source's directory in/var/lib/securedrop/store
.Scenario 1 - Download via "n unread" button on
/
Scenario 2 - Download via "Download Unread" button on
/
Scenario 3 - Download via "Download" button on
/
Scenario 4 - Download via "Download Selected" button on
/col/<filesystem_id>
Scenario 5 - Direct message download from
/col/<filesystem_id>
Deployment
Any special considerations for deployment? Consider both:
Checklist
If you made changes to the server application code:
make lint
) and tests (make test
) pass in the development containerIf you made changes to
securedrop-admin
:make -C admin test
) pass in the admin development containerIf you made changes to the system configuration:
If you made non-trivial code changes:
Test plan above + added unit/functional tests.
If you made changes to documentation:
make docs-lint
) passed locallyIf you added or updated a code dependency:
Choose one of the following: