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

Update to fix view on image validation failure #10009

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jimchamp
Copy link
Collaborator

@jimchamp jimchamp commented Nov 8, 2024

Closes: #10086
Follow-up to #9966

Fixes "Unable to render this page" message being rendered in cover modal when image validation fails.

Technical

Adds validate method to image validator. Replaces existing image validation calls with a single validate call in the upload method.

Validation errors are now propagated from upload to the image upload handler. When a validation error occurs, the covers/add template is rendered with an error message.

Testing

Attempt to upload an invalid image to the covers service. Expect to see a generic error message.

An invalid image has at least one of the following properties:

  • Is greater than 10MB size
  • Ends with an invalid file extension
  • Is not actually an image

Screenshot

Screenshot 2024-11-07 171051

Stakeholders

Adds `validate` method to image validator.  Replaces
existing image validation calls with a single `validate`
call in the `upload` method.

Validation errors are now propagated from `upload` to the
image upload handler.  When a validation error occurs, the
`covers/add` template is rendered with an error message
@cdrini cdrini self-assigned this Nov 11, 2024
openlibrary/plugins/upstream/covers.py Show resolved Hide resolved
data = self.upload(key, i)
try:
data = self.upload(key, i)
except ValueError as e:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, this except now covers more code than before, and ValueError is a somewhat generic error that can also be thrown by native python. I think we now might need to make a custom ImageValidationError to avoid accidentally masking unrelated bugs/ValueErrors.

@cdrini cdrini added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Nov 14, 2024
@github-actions github-actions bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Dec 5, 2024
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.

Error when attempting to upload webp as cover
2 participants