[CLI] Raise error when copy_files source doesn't exist#4186
Merged
Conversation
Previously, `hf buckets cp` would silently succeed when the source file or prefix didn't exist in a bucket (e.g. `hf buckets cp hf://buckets/user/bucket/nonexistent hf://buckets/user/other/file`). This happened because `get_bucket_paths_info` ignores missing paths and `list_bucket_tree` returns nothing for non-existent prefixes, so the operation completed with zero files copied. Now raises `EntryNotFoundError` when no source files are found, consistent with how missing files from repos already error. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Contributor
|
This PR has been shipped as part of the v1.14.0 release. |
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.
Context: reported by @Pierrci in private slack. Copying files from a bucket to another bucket succeeds even if source files does not exist (no-op without failure). Let's fail explicitly.
Before:
After:
Root cause:
get_bucket_paths_infosilently ignores missing paths andlist_bucket_treereturns nothing for non-existent prefixes, socopy_filescompleted with zero operations without error.🤖 Generated with Claude Code
Note
Medium Risk
Changes
copy_filesto raiseEntryNotFoundErrorwhen the remote source path yields no files, which is a behavior change that could break scripts relying on the previous no-op semantics. Impact is limited to copy operations and improves correctness and user feedback.Overview
Makes
hf buckets cp(viaHfApi.copy_files) fail fast when the remotesourcepath does not resolve to any files, raisingEntryNotFoundErrorinstead of silently succeeding with zero operations.Extends CLI error formatting to recognize
EntryNotFoundErrorand adds a regression test asserting the CLI surfaces this exception when copying a non-existent bucket file.Reviewed by Cursor Bugbot for commit d7638ae. Bugbot is set up for automated code reviews on this repo. Configure here.