{"record":{"id":"85e1b95e65c1f2df","repo":"wtfutil/wtf","slug":"failed-to-create-azure-logs-client-for-subscriptio-85e1b9","errorCode":null,"errorMessage":"failed to create Azure Logs client for subscription %s: %w","messagePattern":"failed to create Azure Logs client for subscription (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/azurelogs/session.go","lineNumber":100,"sourceCode":"\n\tsess.Azure.Credential, err = azidentity.NewDefaultAzureCredential(&azidentity.DefaultAzureCredentialOptions{})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// CreateLogsClient creates a cached Azure Log Analytics client for the specified subscription\nfunc CreateLogsClient(sess *Session, subscriptionID string) (*azquery.LogsClient, error) {\n\tif sess.Azure.Credential == nil {\n\t\treturn nil, fmt.Errorf(\"azure credentials not initialized for subscription %s: please set up authentication first\", subscriptionID)\n\t}\n\n\t// Create a new client for this subscription ID using modern Azure SDK\n\tclient, err := azquery.NewLogsClient(sess.Azure.Credential, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Azure Logs client for subscription %s: %w\", subscriptionID, err)\n\t}\n\n\treturn client, nil\n}\n","sourceCodeStart":82,"sourceCodeEnd":105,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/azurelogs/session.go#L82-L105","documentation":"After the credential check, CreateLogsClient calls azquery.NewLogsClient. If the Azure SDK cannot construct the LogsClient (e.g. the credential object itself is invalid) the error is wrapped with this message and the subscription ID. The underlying cause is always in the wrapped %w error from the SDK constructor.","triggerScenarios":"azquery.NewLogsClient(sess.Azure.Credential, nil) returns an error — typically a malformed or unsupported credential implementation passed to the SDK constructor.","commonSituations":"Using an empty or partially-populated azidentity credential; SDK version mismatch where the credential type doesn't satisfy azcore.TokenCredential; nil options leading to unsupported pipeline config in rare setups.","solutions":["Inspect the wrapped %w cause returned alongside this message","Re-create the credential via azidentity.NewDefaultAzureCredential or NewClientSecretCredential and verify its error is nil","Verify the Azure SDK module versions are consistent (go mod tidy / go get -u)"],"exampleFix":"// before\ncred, _ := azidentity.NewDefaultAzureCredential(nil) // error ignored, zero-value cred\nclient, err := azquery.NewLogsClient(cred, nil)\n// after\ncred, err := azidentity.NewDefaultAzureCredential(nil)\nif err != nil {\n    return fmt.Errorf(\"credential setup: %w\", err)\n}\nclient, err := azquery.NewLogsClient(cred, nil)","handlingStrategy":"try-catch","validationCode":"if err != nil {\n    return fmt.Errorf(\"azure credential setup failed: %w\", err)\n}\nif sess.Azure.Credential == nil {\n    return errors.New(\"no azure credential\")\n}","typeGuard":null,"tryCatchPattern":"client, err := CreateLogsClient(sess, subID)\nif err != nil {\n    var respErr *azcore.ResponseError\n    if errors.As(err, &respErr) {\n        log.Printf(\"azure SDK error %d: %v\", respErr.StatusCode, respErr.Error())\n    }\n    return err\n}","preventionTips":["Never ignore the error from azidentity credential constructors","Keep Azure SDK modules on consistent, up-to-date versions (go get -u)"],"tags":["azure","sdk","go"],"backgroundTag":"azure-client-construction-failed","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}