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

Prevent UI crash on FileNotFound errors with Active Storage #4103

Merged
merged 1 commit into from
Aug 29, 2022

Conversation

cpfergus1
Copy link
Contributor

Description
In a previous PR #4026, a fix was implemented to prevent an application from crashing by capturing an exception and providing a replacement image to prevent a non-operable UI. In issue #4095 it was found that the implemented fix did not capture all failure points that may be caused by a corrupt or FileNotFound issue.

This commit adds the ability for the application to catch missing images with Active Storage during an API call should a file become corrupt or deleted without removing the record. This compliments PR #4026 which prevented the same error on the backend. The change will return a json image package with attributes equal to nil and noimage replacements if an
image cannot be sourced. This should be back-ported to 3.0 if cleared for merging.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@cpfergus1 cpfergus1 changed the title Implemented fix for FileNotFound errors with Active Storage Prevent UI crash on FileNotFound errors with Active Storage Jun 15, 2021
@cpfergus1 cpfergus1 force-pushed the patch-image-file-not-found branch 3 times, most recently from 01503ad to 072b0aa Compare June 16, 2021 12:52
@cpfergus1 cpfergus1 force-pushed the patch-image-file-not-found branch 5 times, most recently from e75b537 to 0d8ad7c Compare September 14, 2021 00:39
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@cpfergus1 thanks for working on this issue!

Unless we want to patch ActiveStorage directly, this change looks reasonable to me.
Also, having nil instead of 0 for height and width seems to be the right way to me.
On the other hand, not really sure we want nil for identified and analyzed, for example the latter seems to be always set to true by rails, after extracting the image metadata.
Do you have any opinion on this?

@waiting-for-dev waiting-for-dev added the type:bug Error, flaw or fault label Aug 24, 2022
@cpfergus1
Copy link
Contributor Author

@cpfergus1 thanks for working on this issue!

Unless we want to patch ActiveStorage directly, this change looks reasonable to me. Also, having nil instead of 0 for height and width seems to be the right way to me. On the other hand, not really sure we want nil for identified and analyzed, for example the latter seems to be always set to true by rails, after extracting the image metadata. Do you have any opinion on this?

My thoughts on this are that if the object cannot be found, it cannot be analyzed or identified since it doesn't exist. This behavior can be witnessed on images_controller_spec.rb when examining the image blob. If you attempt to run analyze on it - it will fail due to the image not being found, so the object has not been analyzed.

@cpfergus1 cpfergus1 force-pushed the patch-image-file-not-found branch 7 times, most recently from a3aa5f6 to 00eb433 Compare August 25, 2022 16:21
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Many thanks for your continuous work on it, @cpfergus1! A last minor suggestion, it would be nice to add the id of the attachment in the warning message, so that users can't more easily find it.

It'd be also better to rebase from master before merging 🙏

This commit adds the ability for the application to catch missing
images with Active Storage during an API call should a file become
corrupt or deleted without removing the record through appropriate channels.
This compliments PR solidusio#4026 which prevented the same error on the backend.
The change will return and image with attributes equal to nil and
noimage replacements if an image cannot be sourced.

Reasons for the changes:
- image.attachment.url bypasses rescue check found in ActiveStorageAdapter

- API calls hit height and width prior to url rescue, had to implement
  rescue in Attachment#metadata.
@cpfergus1 cpfergus1 force-pushed the patch-image-file-not-found branch from 00eb433 to c2b06a5 Compare August 26, 2022 13:24
@waiting-for-dev waiting-for-dev added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_core Changes to the solidus_core gem labels Aug 29, 2022
@waiting-for-dev
Copy link
Contributor

Thanks, @cpfergus1. We only need another review. Pinging @kennyadsl as he also looked into it.

@kennyadsl kennyadsl merged commit 499ea68 into solidusio:master Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem changelog:solidus_core Changes to the solidus_core gem type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants