juicedata/juicefs · error

Fail to get location of bucket %q: %s

Error message

Fail to get location of bucket %q: %s

What it means

When the endpoint's region part is exactly "bcebos.com", newBOS calls autoBOSEndpoint to look up the bucket's actual region via the BOS GetBucketLocation API. If that lookup fails (network error, auth failure, bucket missing), construction aborts with this message wrapping the bucket name and error.

Source

Thrown at pkg/object/bos.go:310

		endpoint = fmt.Sprintf("https://%s", endpoint)
	}
	uri, err := url.ParseRequestURI(endpoint)
	if err != nil {
		return nil, fmt.Errorf("Invalid endpoint: %v, error: %v", endpoint, err)
	}
	hostParts := strings.SplitN(uri.Host, ".", 2)
	if len(hostParts) != 2 {
		return nil, fmt.Errorf("Invalid endpoint: %v", endpoint)
	}
	bucketName := hostParts[0]
	if accessKey == "" {
		accessKey = os.Getenv("BDCLOUD_ACCESS_KEY")
		secretKey = os.Getenv("BDCLOUD_SECRET_KEY")
	}
	endpoint = hostParts[1]
	if hostParts[1] == "bcebos.com" {
		if endpoint, err = autoBOSEndpoint(bucketName, accessKey, secretKey); err != nil {
			return nil, fmt.Errorf("Fail to get location of bucket %q: %s", bucketName, err)
		}
	}
	endpoint = fmt.Sprintf("%s://%s", uri.Scheme, endpoint)
	logger.Debugf("Use endpoint: %s", endpoint)
	// endpoint format like https://bj.bcebos.com
	bosClient, err := bos.NewClient(accessKey, secretKey, endpoint)
	if err != nil {
		return nil, err
	}
	bosClient.Config.Retry = bce.NewNoRetryPolicy()
	bosClient.Config.UserAgent = UserAgent
	return &bosclient{bucket: bucketName, c: bosClient}, nil
}

func init() {
	Register("bos", newBOS)
}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Set BDCLOUD_ACCESS_KEY and BDCLOUD_SECRET_KEY (or pass accessKey/secretKey explicitly)
  2. Verify the bucket name exists in your Baidu Cloud account
  3. Use a fully qualified regional endpoint (e.g. mybucket.bj.bcebos.com) to skip the location lookup
  4. Check network connectivity/proxy settings to bcebos.com

Example fix

// before
export BDCLOUD_ACCESS_KEY=
newBOS("mybucket.bcebos.com", "", "", "")
// after
export BDCLOUD_ACCESS_KEY=AKXXX
export BDCLOUD_SECRET_KEY=SKXXX
newBOS("mybucket.bj.bcebos.com", "", "", "")
Defensive patterns

Strategy: validation

Validate before calling

// Go: preflight credentials and bucket before NewBOS
if os.Getenv("BDCLOUD_ACCESS_KEY") == "" || os.Getenv("BDCLOUD_SECRET_KEY") == "" {
    return errors.New("BDCLOUD_ACCESS_KEY / BDCLOUD_SECRET_KEY not set")
}

Try / catch

// Go
obj, err := object.NewBOS("mybucket.bcebos.com", "", "", "")
if err != nil && strings.Contains(err.Error(), "Fail to get location") {
    // check credentials/bucket, use explicit regional endpoint to skip lookup
}

Prevention

When it happens

Trigger: Endpoint like "mybucket.bcebos.com" plus network failure to bcebos.com, wrong/missing BDCLOUD_ACCESS_KEY/BDCLOUD_SECRET_KEY credentials, or the bucket does not exist / belongs to another account.

Common situations: Credentials not set in environment or flags; typo'd bucket name; bucket in a different Baidu Cloud account; corporate firewall blocking the location API call.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/94a284337a9ef43e. Report an issue: GitHub.