Skip to content

Error Codes

When commands fail, the CLI returns structured errors with specific error codes. Understanding these codes helps you diagnose issues quickly.

RangeCategoryDescription
1xxxAuthenticationLogin, credentials, and token issues
2xxxAPIBitbucket API request failures
3xxxGitLocal git operations
4xxxConfigurationConfig file read/write issues
5xxxValidationInvalid input or missing required fields
6xxxContextRepository/workspace detection issues
7xxxNetworkTransport/network failures before API response
8xxxOutput formatting--json fields and --jq evaluation issues
9xxxShell completion / UnknownCompletion install/uninstall failures and uncategorized errors

Message: Authentication required

Cause: You haven’t logged in yet, or your credentials have been cleared.

Solution:

Terminal window
bb auth login

Message: Invalid credentials

Cause: Your credentials were rejected by Bitbucket at request time. This is the code emitted for any 401 response that was not recovered by an OAuth refresh — e.g. a wrong API token, a revoked password, or basic-auth requests with bad credentials.

Solution:

  1. Verify your Bitbucket username
  2. Generate a new API token at Bitbucket API Tokens
  3. Re-authenticate:
Terminal window
bb auth logout
bb auth login

Message: OAuth token expired. Run bb auth login to re-authenticate.

Cause: Specifically: an OAuth access token expired and the reactive refresh attempt also failed (refresh token revoked or expired). For non-OAuth flows, a stale token surfaces as AUTH_INVALID (1002) instead.

Solution:

  1. Re-run bb auth login to perform a fresh OAuth flow
  2. If that also fails, create a new API token in Bitbucket settings and switch auth methods

Message: API request failed

Cause: General network or API failure.

Solution:

Message: Resource not found

Cause: The requested repository, PR, or resource doesn’t exist.

Solution:

  • Check spelling of workspace and repository names
  • Verify the resource exists in Bitbucket
  • Ensure you have access to the repository

Message: Access denied

Cause: Your API token doesn’t have the required permissions.

Solution:

  1. Check your API token scopes at Bitbucket API Tokens
  2. See Token Scopes for the exact scope each bb command requires.
  3. If a scope is missing, mint a new token (you can’t add scopes to an existing one) and re-authenticate with bb auth login.

Message: Rate limit exceeded

Cause: You’ve made too many API requests in a short period.

Solution:

  • Wait a few minutes before retrying
  • For scripts, implement exponential backoff
  • Consider caching results when possible

Message: Bitbucket server error

Cause: Bitbucket’s servers are experiencing issues.

Solution:


Message: Not a git repository

Cause: The current directory is not a git repository, but the command requires one.

Solution:

  • Navigate to a git repository directory, or
  • Use explicit flags: -w <workspace> -r <repo>

Message: Git command failed

Cause: A git operation (clone, fetch, checkout) failed.

Solution:

  • Ensure git is installed and in your PATH
  • Check git error message for details
  • Verify you have proper SSH keys or credentials configured

Message: No Bitbucket remote found

Cause: The repository has no remote pointing to Bitbucket.

Solution:

  • Add a Bitbucket remote:
Terminal window
git remote add origin git@bitbucket.org:workspace/repo.git
  • Or use explicit flags: -w <workspace> -r <repo>

Message: Cannot read config file

Cause: The configuration file is corrupted or unreadable.

Solution:

  1. Check file permissions
  2. If corrupted, delete and recreate:
Terminal window
# macOS/Linux
rm ~/.config/bb/config.json
bb auth login
# Windows
del %APPDATA%\bb\config.json
bb auth login

Message: Cannot write config file

Cause: No write permission to the config directory.

Solution:

  • Check directory permissions
  • Ensure the parent directory exists
  • On shared systems, verify you own the config directory

Message: Invalid configuration key

Cause: Attempted to get/set an unknown configuration key.

Solution: Valid configuration keys are:

  • defaultWorkspace - Default workspace
  • skipVersionCheck - Disable update notifications
  • versionCheckInterval - Days between update checks
Terminal window
bb config set defaultWorkspace myworkspace
bb config list

Message: Required field missing

Cause: A required option or argument was not provided.

Solution: Check command help for required options:

Terminal window
bb <command> --help

Common required fields:

  • bb pr create requires --title
  • bb repo create requires a name argument

Message: Invalid value

Cause: A provided value doesn’t match expected format.

Solution:

  • Check the expected format in command help
  • Common issues:
    • PR ID must be a number
    • State must be one of: OPEN, MERGED, DECLINED, SUPERSEDED

Message: File not found: <path>

Cause: A file referenced by an option (e.g. --file for bb snippet create/edit, --body-file for bb pr edit) doesn’t exist on disk, or a named file isn’t present inside a snippet.

Solution:

  • Verify the path is correct relative to the current working directory
  • For bb snippet view --file <name>, list snippet files first to confirm the name

The context field on this error includes the missing path under file (or bodyFile), which scripts can key on to differentiate it from a generic VALIDATION_INVALID.


Message: Could not determine repository

Cause: The CLI couldn’t figure out which repository to use.

Solution:

  1. Use explicit flags:
Terminal window
bb pr list -w myworkspace -r myrepo
  1. Set a default:
Terminal window
bb config set defaultWorkspace myworkspace
  1. Run from within a cloned Bitbucket repository

See Understanding Repository Context for details.

Message: Could not determine workspace

Cause: The CLI couldn’t figure out which workspace to use.

Solution:

  1. Use the -w flag:
Terminal window
bb repo list -w myworkspace
  1. Set a default workspace:
Terminal window
bb config set defaultWorkspace myworkspace

Message: Network error: Unable to reach Bitbucket API

Cause: The request failed before an HTTP response was received (offline, DNS issue, proxy/TLS issue, etc.).

Solution:

  • Check internet and DNS connectivity
  • Verify proxy/TLS settings if applicable
  • Retry the command after connectivity is restored

Message: jq evaluation failed: <jq compiler error>

Cause: The expression passed to --jq is invalid or produced a runtime error.

Solution:

  • Test the expression interactively against the full output first:
Terminal window
bb pr list --json | jq '<expression>'
  • The embedded jq is jq 1.8.x; module imports (include, import) are not supported.
  • Remember --jq runs after field projection — when combined with --json fields, the input is already a flat array (the wrapper has been dropped).

Message: --jq requires --json or similar formatting validation failure.

Cause: Incompatible combination of output flags.

Solution:

  • --jq requires --json. Add --json (with or without a field list).

Message: Failed to install completions: <reason>

Cause: bb completion install couldn’t write the shell completion hooks — typically because the target shell profile isn’t writable, or the underlying tabtab install failed.

Solution:

  • Check write permissions on your shell rc file (e.g. ~/.zshrc, ~/.bashrc)
  • Re-run with DEBUG=true bb completion install for the underlying error
  • If the issue persists, install completions manually by following your shell’s documentation for tabtab

Message: Failed to uninstall completions: <reason>

Cause: bb completion uninstall couldn’t remove the completion hooks — usually because the rc file isn’t writable or the entry was already removed manually.

Solution:

  • Check write permissions on your shell rc file
  • Manually remove the tabtab block from your shell rc file if needed

Message: An unexpected error occurred

Cause: The CLI encountered an error that doesn’t fit any known category.

Solution:

  • Check the error message for details
  • Retry the command
  • If the issue persists, report it with full debug output:
Terminal window
DEBUG=true bb <your-command> 2>&1

The process exit code is intentionally minimal — 0 for success and 1 for any failure. The numeric error code on this page lives in the JSON error payload’s code field, not in the exit status. To branch on a specific failure mode in a script, parse stderr JSON and read .code.

See Exit Codes in the scripting guide for a full example.

When using the CLI in scripts, check the exit code and handle errors appropriately:

#!/bin/bash
set -e
if ! bb pr list -w myworkspace -r myrepo --json > prs.json 2>&1; then
echo "Failed to list PRs"
exit 1
fi
# Process prs.json...

For JSON output, errors are emitted to stderr and include the error code:

Terminal window
bb pr view 999 --json 2>&1
# {"name":"BBError","code":2002,"message":"Pull request not found"}

Typical JSON error payload fields:

  • name - Error class name
  • code - Numeric CLI error code
  • message - Human-readable message
  • context - Optional structured metadata