fix: handle NoSuchKey error in copyFile to prevent false 500 on move - #272
Merged
Merged
Conversation
When R2 throws a NoSuchKey error without $metadata.httpStatusCode, the 404 check was silently failing, causing the error to propagate as a rejected promise in moveObject and returning a 500 partial_failure response. Now also checks e.name === 'NoSuchKey' and returns a normalised 404 metadata object so moveObject treats missing source keys as expected skips. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
bosschaert
approved these changes
May 5, 2026
adobe-bot
pushed a commit
that referenced
this pull request
May 5, 2026
## [1.7.2](v1.7.1...v1.7.2) (2026-05-05) ### Bug Fixes * handle NoSuchKey error name in copyFile catch block ([#272](#272)) ([939b491](939b491)) * increase writeAuditEntry 412 retries to 5 and remove dead retry loop in put.js ([#274](#274)) ([2aca684](2aca684)) * return 400 when label is missing in POST /versionsource ([#273](#273)) ([36acb2b](36acb2b))
Collaborator
|
🎉 This PR is included in version 1.7.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
copyFilecatch block insrc/storage/object/copy.jsto also handle errors wheree.name === 'NoSuchKey'(and$metadata.httpStatusCodeis absent), returning{ $metadata: { httpStatusCode: 404 } }instead of re-throwingmoveObjectfrom receiving a rejected promise for missing source keys, which previously caused a spurious 500partial_failureresponseTest plan
test/storage/object/copy.test.js: verifiescopyFilereturns{ $metadata: { httpStatusCode: 404 } }whenCopyObjectCommandthrowsNoSuchKeywith no$metadata.httpStatusCodetest/storage/object/move.test.js: verifiesmoveObjectreturns 204 when source keys return 404 (the fixedcopyFilereturn value)npm run lint— no errorsnpm test— 371 tests passing, 0 failing🤖 Generated with Claude Code