{"record":{"id":"0f52b1b514850e6d","repo":"wtfutil/wtf","slug":"failed-to-execute-azure-query-w","errorCode":null,"errorMessage":"failed to execute Azure query: %w","messagePattern":"failed to execute Azure query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/azurelogs/widget.go","lineNumber":73,"sourceCode":"\twidget.dataLoaded = false\n\twidget.tableData = nil\n\n\twidget.Redraw(widget.content)\n}\n\n/* -------------------- Helper Functions -------------------- */\n\nfunc (widget *Widget) fetchDataAsync() {\n\tsess, err := Init(to.Ptr(widget.settings.Queryfile))\n\tif err != nil {\n\t\twidget.setError(fmt.Errorf(\"failed to initialize Azure session: %w\", err))\n\t\treturn\n\t}\n\n\t// Execute Azure query directly\n\ttableResp, err := RunQuery(sess)\n\tif err != nil {\n\t\twidget.setError(fmt.Errorf(\"failed to execute Azure query: %w\", err))\n\t\treturn\n\t}\n\n\t// Check if we have valid data structure\n\tif tableResp == nil || len(tableResp.Header) == 0 {\n\t\twidget.setError(fmt.Errorf(\"no table structure returned from query\"))\n\t\treturn\n\t}\n\n\t// Store the data and mark as loaded\n\twidget.tableData = tableResp\n\twidget.dataLoaded = true\n\twidget.loading = false\n\twidget.Redraw(widget.content)\n}\n\n// setError is a helper function to set error state and trigger redraw\nfunc (widget *Widget) setError(err error) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/azurelogs/widget.go#L55-L91","documentation":"fetchDataAsync wraps any error from RunQuery (which calls CreateLogsClient and executes the Log Analytics Kusto query) as 'failed to execute Azure query'. The real cause — bad credentials, invalid KQL, network/HTTP failure, or client construction failure — is inside the wrapped %w error.","triggerScenarios":"RunQuery(sess) returns an error during widget refresh: CreateLogsClient failed (nil credentials), the KQL query is rejected by Log Analytics, or the HTTP request to the Azure API fails.","commonSituations":"Expired az login token; subscription/workspace misconfigured in the query file; malformed KQL syntax; corporate proxy blocking api.loganalytics.io.","solutions":["Unwrap the returned error to see the underlying cause (errors.Unwrap / %v of the chain)","Re-authenticate (az login) or fix service-principal credentials","Validate the KQL query in Azure Log Analytics portal before running it via the widget","Check network/proxy access to the Log Analytics endpoint"],"exampleFix":"// before\nq := \"requests | where timestamp > ago(1h) | take\" // truncated KQL\ntableResp, err := RunQuery(sess)\n// after\nq := \"requests | where timestamp > ago(1h) | take 100\"\ntableResp, err := RunQuery(sess)\nif err != nil {\n    log.Printf(\"azure query failed: %v\", err)\n    return\n}","handlingStrategy":"retry","validationCode":"if err := validateKQL(widget.settings.Query); err != nil {\n    return fmt.Errorf(\"invalid query: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"tableResp, err := RunQuery(sess)\nif err != nil {\n    if isTransient(err) { // e.g. net.Error or 5xx ResponseError\n        time.AfterFunc(backoff, func() { widget.fetchDataAsync() })\n        return\n    }\n    widget.setError(fmt.Errorf(\"failed to execute Azure query: %w\", err))\n    return\n}","preventionTips":["Test the KQL query in the Azure portal before wiring it into the widget","Re-authenticate on 401 responses instead of surfacing a permanent error","Use bounded exponential backoff for transient network failures"],"tags":["azure","kusto","network","go"],"backgroundTag":"azure-query-execution-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"}