wtfutil/wtf · error

failed to execute Azure query: %w

Error message

failed to execute Azure query: %w

What it means

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.

Source

Thrown at modules/azurelogs/widget.go:73

	widget.dataLoaded = false
	widget.tableData = nil

	widget.Redraw(widget.content)
}

/* -------------------- Helper Functions -------------------- */

func (widget *Widget) fetchDataAsync() {
	sess, err := Init(to.Ptr(widget.settings.Queryfile))
	if err != nil {
		widget.setError(fmt.Errorf("failed to initialize Azure session: %w", err))
		return
	}

	// Execute Azure query directly
	tableResp, err := RunQuery(sess)
	if err != nil {
		widget.setError(fmt.Errorf("failed to execute Azure query: %w", err))
		return
	}

	// Check if we have valid data structure
	if tableResp == nil || len(tableResp.Header) == 0 {
		widget.setError(fmt.Errorf("no table structure returned from query"))
		return
	}

	// Store the data and mark as loaded
	widget.tableData = tableResp
	widget.dataLoaded = true
	widget.loading = false
	widget.Redraw(widget.content)
}

// setError is a helper function to set error state and trigger redraw
func (widget *Widget) setError(err error) {

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Unwrap the returned error to see the underlying cause (errors.Unwrap / %v of the chain)
  2. Re-authenticate (az login) or fix service-principal credentials
  3. Validate the KQL query in Azure Log Analytics portal before running it via the widget
  4. Check network/proxy access to the Log Analytics endpoint

Example fix

// before
q := "requests | where timestamp > ago(1h) | take" // truncated KQL
tableResp, err := RunQuery(sess)
// after
q := "requests | where timestamp > ago(1h) | take 100"
tableResp, err := RunQuery(sess)
if err != nil {
    log.Printf("azure query failed: %v", err)
    return
}
Defensive patterns

Strategy: retry

Validate before calling

if err := validateKQL(widget.settings.Query); err != nil {
    return fmt.Errorf("invalid query: %w", err)
}

Try / catch

tableResp, err := RunQuery(sess)
if err != nil {
    if isTransient(err) { // e.g. net.Error or 5xx ResponseError
        time.AfterFunc(backoff, func() { widget.fetchDataAsync() })
        return
    }
    widget.setError(fmt.Errorf("failed to execute Azure query: %w", err))
    return
}

Prevention

When it happens

Trigger: 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.

Common situations: Expired az login token; subscription/workspace misconfigured in the query file; malformed KQL syntax; corporate proxy blocking api.loganalytics.io.

Related errors


AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03). Data as JSON: /api/errors/0f52b1b514850e6d. Report an issue: GitHub.