wtfutil/wtf · error
failed to create Azure Logs client for subscription %s: %w
Error message
failed to create Azure Logs client for subscription %s: %w
What it means
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.
Source
Thrown at modules/azurelogs/session.go:100
sess.Azure.Credential, err = azidentity.NewDefaultAzureCredential(&azidentity.DefaultAzureCredentialOptions{})
if err != nil {
return err
}
return nil
}
// CreateLogsClient creates a cached Azure Log Analytics client for the specified subscription
func CreateLogsClient(sess *Session, subscriptionID string) (*azquery.LogsClient, error) {
if sess.Azure.Credential == nil {
return nil, fmt.Errorf("azure credentials not initialized for subscription %s: please set up authentication first", subscriptionID)
}
// Create a new client for this subscription ID using modern Azure SDK
client, err := azquery.NewLogsClient(sess.Azure.Credential, nil)
if err != nil {
return nil, fmt.Errorf("failed to create Azure Logs client for subscription %s: %w", subscriptionID, err)
}
return client, nil
}
View on GitHub (pinned to bb838c1ccb)
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)
Example fix
// before
cred, _ := azidentity.NewDefaultAzureCredential(nil) // error ignored, zero-value cred
client, err := azquery.NewLogsClient(cred, nil)
// after
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return fmt.Errorf("credential setup: %w", err)
}
client, err := azquery.NewLogsClient(cred, nil) Defensive patterns
Strategy: try-catch
Validate before calling
if err != nil {
return fmt.Errorf("azure credential setup failed: %w", err)
}
if sess.Azure.Credential == nil {
return errors.New("no azure credential")
} Try / catch
client, err := CreateLogsClient(sess, subID)
if err != nil {
var respErr *azcore.ResponseError
if errors.As(err, &respErr) {
log.Printf("azure SDK error %d: %v", respErr.StatusCode, respErr.Error())
}
return err
} Prevention
- Never ignore the error from azidentity credential constructors
- Keep Azure SDK modules on consistent, up-to-date versions (go get -u)
When it happens
Trigger: azquery.NewLogsClient(sess.Azure.Credential, nil) returns an error — typically a malformed or unsupported credential implementation passed to the SDK constructor.
Common situations: 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.
Related errors
- azure credentials not initialized for subscription %s: pleas
- failed to initialize Azure session: %w
- failed to execute Azure query: %w
- no table structure returned from query
- invalid app index selected
AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03).
Data as JSON: /api/errors/85e1b95e65c1f2df.
Report an issue: GitHub.