{"record":{"id":"dec10bdbdc55ce41","repo":"wtfutil/wtf","slug":"azure-credentials-not-initialized-for-subscription","errorCode":null,"errorMessage":"azure credentials not initialized for subscription %s: please set up authentication first","messagePattern":"azure credentials not initialized for subscription (.+?): please set up authentication first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/azurelogs/session.go","lineNumber":94,"sourceCode":"\t\t\t&azidentity.ClientSecretCredentialOptions{})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn nil\n\t}\n\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":76,"sourceCodeEnd":105,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/azurelogs/session.go#L76-L105","documentation":"CreateLogsClient builds a cached Azure Log Analytics (azquery.LogsClient) for a subscription. Before constructing the client it checks that the Azure credential chain on the Session has been initialized; if sess.Azure.Credential is nil it refuses to proceed with this error instead of panicking inside the SDK. It means authentication setup (Init/credential load) was skipped or failed earlier.","triggerScenarios":"Calling CreateLogsClient (directly or via RunQuery) on a Session whose Azure.Credential is nil — e.g. Init() was never called, failed silently, or a Session struct was constructed manually without running the authentication setup.","commonSituations":"Missing AZURE_CLIENT_ID/AZURE_TENANT_ID/AZURE_CLIENT_SECRET or az login in CI; widget code instantiating its own Session instead of calling Init; tests creating a bare &Session{}; credentials nil because an earlier Init error was ignored.","solutions":["Call Init() (or the equivalent credential setup) before CreateLogsClient and check its error","Run `az login` locally or configure Azure service-principal env vars in CI","Inspect the Session to ensure sess.Azure.Credential is non-nil before querying"],"exampleFix":"// before\nsess := &azurelogs.Session{}\nclient, err := azurelogs.CreateLogsClient(sess, subID) // error: credentials not initialized\n// after\nsess, err := azurelogs.Init(&queryfile)\nif err != nil {\n    return err\n}\nclient, err := azurelogs.CreateLogsClient(sess, subID)","handlingStrategy":"validation","validationCode":"if sess == nil || sess.Azure == nil || sess.Azure.Credential == nil {\n    return errors.New(\"azure credentials not initialized: call Init() first\")\n}\nclient, err := CreateLogsClient(sess, subscriptionID)","typeGuard":"func hasAzureCred(sess *Session) bool {\n    return sess != nil && sess.Azure != nil && sess.Azure.Credential != nil\n}","tryCatchPattern":null,"preventionTips":["Always construct sessions via Init(), never by struct literal","Check the error returned by Init() before proceeding","Add a startup assertion that Azure credentials are present in long-running apps"],"tags":["azure","authentication","go"],"backgroundTag":"missing-azure-credentials","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"}