Skip to content

fix: handle NoSuchKey error in copyFile to prevent false 500 on move - #272

Merged
kptdobe merged 1 commit into
mainfrom
worktree-agent-ae4c61d22d44b2c01
May 5, 2026
Merged

kptdobe merged 1 commit into
mainfrom
worktree-agent-ae4c61d22d44b2c01

Conversation

@kptdobe

@kptdobe kptdobe commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extends the copyFile catch block in src/storage/object/copy.js to also handle errors where e.name === 'NoSuchKey' (and $metadata.httpStatusCode is absent), returning { $metadata: { httpStatusCode: 404 } } instead of re-throwing
  • Prevents moveObject from receiving a rejected promise for missing source keys, which previously caused a spurious 500 partial_failure response

Test plan

  • New test in test/storage/object/copy.test.js: verifies copyFile returns { $metadata: { httpStatusCode: 404 } } when CopyObjectCommand throws NoSuchKey with no $metadata.httpStatusCode
  • New test in test/storage/object/move.test.js: verifies moveObject returns 204 when source keys return 404 (the fixed copyFile return value)
  • npm run lint — no errors
  • npm test — 371 tests passing, 0 failing

🤖 Generated with Claude Code

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

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kptdobe
kptdobe requested a review from bosschaert May 4, 2026 09:28
@kptdobe
kptdobe merged commit 939b491 into main May 5, 2026
6 checks passed
@kptdobe
kptdobe deleted the worktree-agent-ae4c61d22d44b2c01 branch May 5, 2026 09:50
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))
@adobe-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.7.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants