{"record":{"id":"5cb0226675d72de5","repo":"juicedata/juicefs","slug":"failed-to-create-azure-blob-client-with-token-cred","errorCode":null,"errorMessage":"Failed to create Azure blob client with token credential: %v","messagePattern":"Failed to create Azure blob client with token credential: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/object/azure.go","lineNumber":364,"sourceCode":"\t\t\t}\n\t\t\treturn &wasb{container: client.ServiceClient().NewContainerClient(containerName), azblobCli: client, cName: containerName, useTokenAuth: true}, nil\n\t\t}\n\n\t\ttokenCred, err := createAzureCredential()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Failed to create Azure credential (managed identity/Azure CLI): %v\", err)\n\t\t}\n\t\tif domain == \"\" {\n\t\t\tif domain, err = autoWasbEndpoint(accountName, uri.Scheme, func(serviceURL string) (*azblob.Client, error) {\n\t\t\t\treturn azblob.NewClient(serviceURL, tokenCred, nil)\n\t\t\t}); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"Unable to get endpoint of container %s: %s\", containerName, err)\n\t\t\t}\n\t\t}\n\t\tserviceURL := fmt.Sprintf(\"%s://%s.%s\", uri.Scheme, accountName, domain)\n\t\tclient, err := azblob.NewClient(serviceURL, tokenCred, azblobOptions())\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Failed to create Azure blob client with token credential: %v\", err)\n\t\t}\n\t\treturn &wasb{container: client.ServiceClient().NewContainerClient(containerName), azblobCli: client, cName: containerName, useTokenAuth: true}, nil\n\t}\n\n\t// Priority 3: Shared key authentication\n\tcredential, err := azblob.NewSharedKeyCredential(accountName, accountKey)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdomain := domainFromHost(hostParts)\n\tif domain == \"\" {\n\t\tif domain, err = autoWasbEndpoint(accountName, uri.Scheme, func(serviceURL string) (*azblob.Client, error) {\n\t\t\treturn azblob.NewClientWithSharedKeyCredential(serviceURL, credential, nil)\n\t\t}); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Unable to get endpoint of container %s: %w\", containerName, err)\n\t\t}\n\t}\n\tclient, err := azblob.NewClientWithSharedKeyCredential(fmt.Sprintf(\"%s://%s.%s\", uri.Scheme, accountName, domain), credential, azblobOptions())","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/object/azure.go#L346-L382","documentation":"Thrown when azblob.NewClient(serviceURL, tokenCred, azblobOptions()) rejects the assembled service URL or options, after credential creation and endpoint discovery succeeded. Indicates a malformed final service URL.","triggerScenarios":"newWasb token-auth path where fmt.Sprintf(\"%s://%s.%s\", scheme, accountName, domain) produces a URL the SDK cannot parse — typically an empty account name or domain.","commonSituations":"Empty account name in the endpoint config; scheme other than http/https; auto-discovered domain empty due to a probe that returned no usable value.","solutions":["Ensure the account name is non-empty and contains only valid characters.","Confirm the endpoint scheme is https (or http for emulators).","Use an explicit full domain in the endpoint instead of relying on discovery.","Log/print the constructed serviceURL to verify its shape before calling NewClient."],"exampleFix":"// before\nazblob:///  (empty account)\n// after\nazblob://myaccount.blob.core.windows.net","handlingStrategy":"validation","validationCode":"if accountName == \"\" { return errors.New(\"account name is required\") }\nserviceURL := fmt.Sprintf(\"%s://%s.%s\", scheme, accountName, domain)\nif _, err := url.Parse(serviceURL); err != nil { return fmt.Errorf(\"bad service URL %q: %w\", serviceURL, err) }","typeGuard":null,"tryCatchPattern":"client, err := azblob.NewClient(serviceURL, tokenCred, opts)\nif err != nil {\n    return fmt.Errorf(\"invalid service URL %q: %w\", serviceURL, err)\n}","preventionTips":["Validate account name is non-empty and URL-safe","Pin the endpoint scheme to https","Log the assembled serviceURL (redacted) on failure"],"tags":["azure","object-storage","url-validation","sdk-client"],"backgroundTag":"invalid-url","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}