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

Rescue FileNotFoundError exception on failed image downloads #4026

Merged
merged 1 commit into from
Apr 15, 2021

Conversation

cpfergus1
Copy link
Contributor

@cpfergus1 cpfergus1 commented Apr 13, 2021

Description
This PR aimed to solve the Active::Storage::FileNotFoundError bug described in Issue #4017 by to handling FileNotFound error when ActiveStorage fails to download from a remote service such as S3.

In rare circumstances, an image would fail to upload to a third party storage service, causing the application to hard crash when trying to retrieve an image resource. This commit implements a fix to return a place holder image to alert the user of an error and also prevents the application from crashing. This fix will not, however, save any errors associated with the failed upload such as credential errors. This fix was tested by artificially changing the blob record to force
a FileNotFoundError.

The handling of the FileNotFound error maybe a temporary fix as we are aiming to discover another pathway to handle the exception and remove the invalid objects simultaneously.

image

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
Copy link
Contributor Author

cpfergus1 commented Apr 13, 2021

Failed on Paperclip

Failure/Error: Spree::Image.first.attachment.blob.update(key: 11)

NoMethodError:
  undefined method `blob' for #<Paperclip::Attachment:0x00005611dcae1bd8>
./spec/features/admin/products/edit/images_spec.rb:79:in `block (3 levels) in <top (required)>'

end

click_button "Update"
Spree::Image.first.attachment.blob.update(key: 11)
Copy link
Member

Choose a reason for hiding this comment

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

Specs are failing in the CI in jobs where we do not use Active Storage but Paperclip. In that case, attachment doesn't respond to blob and it fails.

I think we need to find a way to make this compatible with both or skip the test when we are using Paperclip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Skipping test based on which module is used.

@kennyadsl kennyadsl added changelog:solidus_core Changes to the solidus_core gem Needs Backport labels Apr 14, 2021
In rare circumstances, an image would fail to upload to a third party
storage service, causing the application to hard crash when trying to
retrieve an image resource. This commit implements a fix to return a
place holder image to alert the user of an error and also prevents the
application from crashing. This fix will not, however, save any errors
associated with the failed upload such as credential errors.
This fix was tested by artificially changing the blob record to force
a FileNotFoundError.

Commit History:
Implemented fix for AS::FileNotFound Error"
Implemented feature test for potential FileNotFoundError
Added conditional to test because it is specific to Active Storage
@cpfergus1 cpfergus1 force-pushed the Issue-4017-FileNotFound branch from da8ffac to af78b4b Compare April 14, 2021 15:13
@cpfergus1 cpfergus1 requested a review from kennyadsl April 14, 2021 15:30
@kennyadsl kennyadsl merged commit 3ba6bc6 into solidusio:master Apr 15, 2021
@kennyadsl kennyadsl deleted the Issue-4017-FileNotFound branch April 15, 2021 08:42
@kennyadsl kennyadsl changed the title Patch for FileNotFoundError bug on failed image downloads. Rescue FileNotFoundError exception on failed image downloads Apr 15, 2021
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 15, 2021
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 solidusio#4026](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.
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 15, 2021
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](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.
- metadata returns hash with strings, not symbols caused nil values to be
returned regardless if the image was good or not.
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 15, 2021
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.
- metadata returns hash with strings, not symbols caused nil values to be
returned regardless if the image was good or not.
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 15, 2021
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.
- metadata returns hash with strings, not symbols. It appeared that
this caused nil values to be returned regardless if the image was good or not.
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 15, 2021
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.
- metadata returns hash with strings, not symbols. It appeared that
this caused nil values to be returned regardless if the image was good or not.
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 16, 2021
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.

- metadata returns hash with strings, not symbols. It appeared that
this caused nil values to be returned regardless if the image was good or not.
cpfergus1 added a commit to cpfergus1/solidus that referenced this pull request Jun 16, 2021
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 added a commit to cpfergus1/solidus that referenced this pull request Sep 13, 2021
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 added a commit to cpfergus1/solidus that referenced this pull request Sep 13, 2021
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 added a commit to cpfergus1/solidus that referenced this pull request Sep 14, 2021
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 added a commit to cpfergus1/solidus that referenced this pull request Sep 14, 2021
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 added a commit to cpfergus1/solidus that referenced this pull request Sep 14, 2021
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
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 added a commit to cpfergus1/solidus that referenced this pull request Aug 26, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants