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

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 username or API token is incorrect.

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: Token expired

Cause: Your API token has expired or been revoked.

Solution:

  1. Create a new API token in Bitbucket settings
  2. Re-authenticate with the new token

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. Required scopes depend on the operation:
    • Read operations: account:read, repository:read, pullrequest:read
    • Write operations: repository:write, pullrequest:write
    • Delete operations: repository:admin

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: 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

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