You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Report invalid B2 URI arguments without a traceback - #1224
get_b2_uri_from_arg (used by commands such as file hide with the deprecated bucketName fileName form) raises argparse.ArgumentError after parsing when the B2 URI is invalid or is given together with a file name. run_command didn't handle it, so it fell into the generic except Exception: raise and the user got a traceback.
run_command now catches argparse.ArgumentError, prints it as ERROR: argument B2_URI: ... and returns 2, the same exit code argparse uses for its own argument errors (as in test_file_hide__cannot_hide_by_b2id).
$ b2 file hide notauri
ERROR: argument B2_URI: Incorrect B2 URI was provided, expected `b2://bucketName/fileName`, but got 'notauri'
Tests:
New test_file_hide__invalid_b2_uri_argument covers both messages. It fails on master and passes with the fix, for --cli b2v3, b2v4 and b2v5.
test/unit for b2v3, b2v4 and b2v5: the only failures are the same 7 autocomplete tests that fail on master in my environment.
ruff check and ruff format --check (0.8.6, as in uv.lock) are clean; changelog fragment changelog.d/1216.fixed.md added.
get_b2_uri_from_arg raises argparse.ArgumentError for an invalid B2 URI
or a B2 URI given together with a file name, but run_command re-raised
it, so `b2 file hide notauri` ended in a traceback. Print it as an
error and exit with 2, like other argument errors.
FixesBackblaze#1216
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3
ConsoleTool.run_command now handles command-time argparse.ArgumentError by logging the error, printing its message to stderr, and returning status 2. Parameterized tests cover two invalid file-hide argument cases and verify that the file remains listed. The changelog describes the error and exit behavior.
Severity of issue fixed: Low
Merge Risk: Low · up to 67f59
Invalid B2 URI arguments now produce a short error and exit code 2 instead of a traceback. With --verbose, a traceback may still appear, consistent with other error handlers. This is low risk and mergeable, with owner awareness of the verbose-mode behavior.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title states the main change: invalid B2 URI arguments are now reported as a short error instead of a traceback. The raw summary confirms that run_command now catches argparse.ArgumentError, print…
Description check
The description explains the cause: get_b2_uri_from_arg raises argparse.ArgumentError for an invalid B2 URI or a URI given with a file name, and run_command did not handle it, so users saw a traceback…
Linked Issues check
Issue #1216 asks that invalid B2 URI arguments, or a B2 URI given together with a file name, produce a short error instead of a traceback. The whole-PR diff (merge base to head) adds an `except argpar…
Out of Scope Changes check
The whole-PR changes are limited to three areas. (1) b2/_internal/console_tool.py: the new except argparse.ArgumentError branch in run_command. This is the direct fix for #1216. (2) test/unit/cons…
Full details: Title check
Explanation
The title states the main change: invalid B2 URI arguments are now reported as a short error instead of a traceback. The raw summary confirms that run_command now catches argparse.ArgumentError, prints an ERROR message, and returns exit status 2, which matches the title.
Full details: Description check
Explanation
The description explains the cause: get_b2_uri_from_arg raises argparse.ArgumentError for an invalid B2 URI or a URI given with a file name, and run_command did not handle it, so users saw a traceback. It states the fix (catching the error, printing an ERROR line, returning 2), gives an example, and lists the tests added. It relates directly to the changeset.
Full details: Linked Issues check
Explanation
Issue #1216 asks that invalid B2 URI arguments, or a B2 URI given together with a file name, produce a short error instead of a traceback. The whole-PR diff (merge base to head) adds an except argparse.ArgumentError branch to ConsoleTool.run_command in b2/_internal/console_tool.py. The branch prints ERROR: {e} to stderr and returns 2. The exception text comes from get_b2_uri_from_arg, so the output has the form ERROR: argument B2_URI: .... The new test test_file_hide__invalid_b2_uri_argument in test/unit/console_tool/test_file_hide.py checks both cases: a URI with a file name, and the invalid string notauri. It expects the matching stderr text and status 2. The issue example commands are covered by this path. The issue does not fix an exit code; the PR uses 2, which matches argparse argument errors. The PR author reports the test results in the PR description. I did not run the tests. The requirement is met by the code and test at the reviewed head.
Full details: Out of Scope Changes check
Explanation
The whole-PR changes are limited to three areas. (1) b2/_internal/console_tool.py: the new except argparse.ArgumentError branch in run_command. This is the direct fix for #1216. (2) test/unit/console_tool/test_file_hide.py: a parameterized test for the two invalid URI cases in #1216. (3) changelog.d/1216.fixed.md: a changelog fragment for the fix. All three changes connect directly to #1216. No unrelated code changes appear in the reviewed diff for console_tool.py or test_file_hide.py. The changelog file was not inspected directly; its content comes from the change summary only.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
b2/_internal/console_tool.py-5593-5593: 1
5593-5593: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Do not log a traceback for an argument error.
When the user supplies --verbose with an invalid URI, the stderr logging handler prints the traceback from logger.exception. The command therefore still shows a traceback despite returning status 2. Log the error without exception information, and cover the verbose case in the test.
As per the PR objectives, invalid URI arguments should produce a short error instead of a traceback.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 4efcad87-e840-4885-a2a2-673bee930b55
Commits
Reviewing files that changed from the base of the PR and between 9194ec5 and 67f590b.
Files selected for processing: 3
b2/_internal/console_tool.py
changelog.d/1216.fixed.md
test/unit/console_tool/test_file_hide.py
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
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
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.
Fixes #1216
get_b2_uri_from_arg(used by commands such asfile hidewith the deprecatedbucketName fileNameform) raisesargparse.ArgumentErrorafter parsing when the B2 URI is invalid or is given together with a file name.run_commanddidn't handle it, so it fell into the genericexcept Exception: raiseand the user got a traceback.run_commandnow catchesargparse.ArgumentError, prints it asERROR: argument B2_URI: ...and returns 2, the same exit code argparse uses for its own argument errors (as intest_file_hide__cannot_hide_by_b2id).Tests:
test_file_hide__invalid_b2_uri_argumentcovers both messages. It fails onmasterand passes with the fix, for--cli b2v3,b2v4andb2v5.test/unitfor b2v3, b2v4 and b2v5: the only failures are the same 7 autocomplete tests that fail onmasterin my environment.ruff checkandruff format --check(0.8.6, as inuv.lock) are clean; changelog fragmentchangelog.d/1216.fixed.mdadded.I used Claude to help write and test this change.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3