Skip to content

🐛 Return 400 instead of 500 when ImageMagick fails on invalid images#10643

Open
niwinz wants to merge 1 commit into
stagingfrom
issue-10642
Open

🐛 Return 400 instead of 500 when ImageMagick fails on invalid images#10643
niwinz wants to merge 1 commit into
stagingfrom
issue-10642

Conversation

@niwinz

@niwinz niwinz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Note: This PR was created with AI assistance

What

When uploading an image that ImageMagick cannot process (e.g., corrupted PNG with invalid IHDR data), the backend returned HTTP 500 with error code imagemagick-error. The frontend treated this as a server error and displayed the full error page instead of showing a user-friendly notification banner.

This PR changes the error to return HTTP 400 with validation error code invalid-image, so the frontend shows a proper error banner.

Why

ImageMagick failures on malformed or oversized images are expected errors caused by user input, not internal server failures. They should be treated as validation errors (HTTP 400) rather than internal errors (HTTP 500).

How

  • Changed exec-magick! in backend/src/app/media.clj to raise :type :validation, :code :invalid-image instead of :type :internal, :code :imagemagick-error
  • Added :invalid-image case to process-error in frontend/src/app/main/data/media.cljs (used by profile/team photo uploads)
  • Updated test assertion in backend/test/backend_tests/media_test.clj to expect :validation type

Closes #10642

When ImageMagick fails to process an uploaded image (e.g., corrupted PNG
with invalid IHDR data), the backend was raising :type :internal with
:code :imagemagick-error, which mapped to HTTP 500. The frontend treated
this as a server error and displayed the full error page.

Changed exec-magick! to raise :type :validation with :code :invalid-image
instead. This flows through the existing :invalid-image handler in
errors.clj which returns HTTP 400. The frontend's handle-media-error and
process-error now catch this code and show a notification banner.

AI-assisted-by: qwen3.7-plus
@niwinz niwinz added this to Main Jul 10, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Main Jul 10, 2026
@niwinz niwinz moved this from Backlog to In progress in Main Jul 10, 2026
@niwinz niwinz added this to the 2.17.0 milestone Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

ImageMagick errors return 500 instead of 400 when uploading invalid images

1 participant