Skip to content

plugin-cloud-storage: silent data loss when user afterChange hook throws during upload #16573

@LimChorngUan

Description

@LimChorngUan

Describe the Bug

When @payloadcms/plugin-cloud-storage is enabled on a collection with a user defined afterChange hook that can throw in certain condition, the throw is swallowed by the plugin (logged at warn) while Payload silently rolls back, leaving S3 and the UI in broken states with no user visible error.

Link to the code that reproduces this issue

https://github.com/LimChorngUan/payload/blob/repro-cloud-storage/test/_community/collections/Media/index.ts

Note that in the repro code, skipCloudStorage flag is set to make the hook fire only on the plugin's internal update, not on the user's outer call.

Reproduction Steps

  1. docker compose -f test/docker-compose.yml up -d localstack mongodb mongot
  2. pnpm run dev _community

Two scenarios:
Newly upload media

  1. Create a new media
  2. Upload a file
  3. Hit save
  4. Observe you being thrown out of the creation page to the media collection list view page
  5. Observe the server log: Failed to persist upload data for collection media document : bla bla bla...

Reupload media

  1. Access an existing media
  2. Reupload with a new file
  3. Hit save
  4. At first glance it looks okay, but observe the server log: Failed to persist upload data for collection media document : bla bla bla...
  5. Refresh the page
  6. The image file is broken
  7. Both the old and new images are no longer be found in s3
Screen.Recording.2026-05-11.at.18.14.09.mov

Which area(s) are affected?

plugin: cloud-storage

Environment Info

I have run on v4 and v3.82, both are reproducible

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions