juicedata/juicefs · error

fail to initialize OBS: %q

Error message

fail to initialize OBS: %q

What it means

After endpoint and proxy setup, newOBS instantiates the Huawei OBS SDK client with obs.New. Any SDK-level initialization failure (bad credentials format, invalid config, transport issues) is wrapped as 'fail to initialize OBS: <err>'. Notably retry is disabled (WithMaxRetryCount(0)) because the SDK does not Seek(0,0) before PUT retries.

Source

Thrown at pkg/object/obs.go:434

	if uri, err = url.ParseRequestURI(endpoint); err != nil {
		return nil, fmt.Errorf("invalid endpoint %s: %q", endpoint, err)
	}
	proxyURL, err := httpproxy.FromEnvironment().ProxyFunc()(uri)
	if err != nil {
		return nil, fmt.Errorf("get proxy url for endpoint: %s error: %q", endpoint, err)
	}
	var urlString string
	if proxyURL != nil {
		urlString = proxyURL.String()
	}

	// Empty proxy url string has no effect
	// there is a bug in the retry of PUT (did not call Seek(0,0) before retry), so disable the retry here
	c, err := obs.New(accessKey, secretKey, endpoint, obs.WithSecurityToken(token),
		obs.WithProxyUrl(urlString), obs.WithMaxRetryCount(0), obs.WithUserAgent(UserAgent),
		obs.WithHttpTransport(httpClient.Transport.(*http.Transport)))
	if err != nil {
		return nil, fmt.Errorf("fail to initialize OBS: %q", err)
	}
	var checkEtag bool
	if _, err = c.GetBucketEncryption(bucketName); err != nil {
		if obsError, ok := err.(obs.ObsError); ok && obsError.Code == "NoSuchEncryptionConfiguration" {
			checkEtag = true
		} else if !ok || obsError.Code != "NoSuchBucket" {
			logger.Warnf("get bucket encryption: %q", err)
		}
	}
	return &obsClient{bucket: bucketName, region: region, checkEtag: checkEtag, c: c}, nil
}

func init() {
	Register("obs", newOBS)
}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Read the wrapped %q error from the SDK for the exact cause
  2. Verify access key, secret key, and security token are set and well-formed
  3. Ensure the default http client transport is an *http.Transport (custom transports can break WithHttpTransport)
  4. Try upgrading/downgrading the obs SDK dependency if init fails with valid inputs
Defensive patterns

Strategy: try-catch

Validate before calling

if ak == "" || sk == "" { return errors.New("obs credentials required") }
if _, ok := httpClient.Transport.(*http.Transport); !ok { return errors.New("transport must be *http.Transport") }

Try / catch

store, err := object.CreateStorage("obs", endpoint, ak, sk, token)
if err != nil && strings.Contains(err.Error(), "fail to initialize OBS") {
	// inspect wrapped SDK error; fix credentials/token/transport
}

Prevention

When it happens

Trigger: obs.New returning an error for the given accessKey/secretKey/token/endpoint/transport — e.g. invalid security token, nil or incompatible http.Transport passed via WithHttpTransport, or SDK config validation failure.

Common situations: Empty or malformed access/secret keys; expired security token; custom transport not an *http.Transport (httpClient.Transport assertion assumptions); SDK version incompatibility.

Related errors


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