Skip to content

[CLI] Raise error when copy_files source doesn't exist#4186

Merged
Wauplin merged 2 commits intomainfrom
fix/cp-missing-source-error
May 6, 2026
Merged

[CLI] Raise error when copy_files source doesn't exist#4186
Wauplin merged 2 commits intomainfrom
fix/cp-missing-source-error

Conversation

@Wauplin
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin commented May 5, 2026

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:

$ hf buckets cp hf://buckets/Wauplin/bucket-raw/models/gpt2/donotexist hf://buckets/huggingface/hf-cli-failures/model.safetensors
✓ Copied
  src: hf://buckets/Wauplin/bucket-raw/models/gpt2/donotexist
  dst: hf://buckets/huggingface/hf-cli-failures/model.safetensors

After:

$ hf buckets cp hf://buckets/Wauplin/bucket-raw/models/gpt2/donotexist hf://buckets/huggingface/hf-cli-failures/model.safetensors
Error: No files found at 'hf://buckets/Wauplin/bucket-raw/models/gpt2/donotexist' in bucket 'Wauplin/bucket-raw'.

Root cause: get_bucket_paths_info silently ignores missing paths and list_bucket_tree returns nothing for non-existent prefixes, so copy_files completed with zero operations without error.

🤖 Generated with Claude Code


Note

Medium Risk
Changes copy_files to raise EntryNotFoundError when 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 (via HfApi.copy_files) fail fast when the remote source path does not resolve to any files, raising EntryNotFoundError instead of silently succeeding with zero operations.

Extends CLI error formatting to recognize EntryNotFoundError and 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.

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]>
@Wauplin Wauplin requested review from Pierrci and hanouticelina May 5, 2026 08:47
@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment Bot commented May 5, 2026

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.

Copy link
Copy Markdown
Member

@Pierrci Pierrci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Wauplin Wauplin merged commit fadab7a into main May 6, 2026
21 checks passed
@Wauplin Wauplin deleted the fix/cp-missing-source-error branch May 6, 2026 09:27
@huggingface-hub-bot
Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.14.0 release.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants