wtfutil/wtf · error

failed to initialize Azure session

Error message

failed to initialize Azure session: %w

What it means

The Azure Logs widget's fetchDataAsync initializes a session with Init(to.Ptr(widget.settings.Queryfile)) before querying. If Init fails (bad queryfile, missing Azure credentials/config) the failure is wrapped as 'failed to initialize Azure session' and surfaced in the widget via setError. It indicates the widget cannot even begin authenticating to Azure.

Solutions

  1. Set a valid Queryfile path in the widget settings and confirm the file exists and parses
  2. Run az login or export AZURE_* service-principal variables for the process running the widget
  3. Call Init() manually with the same queryfile to see the raw underlying error

Example fix

// before
settings.Queryfile = "" // unset in config
sess, err := Init(to.Ptr(widget.settings.Queryfile))
// after
// wtfutil config:
//   queryfile: "~/.config/wtf/azure-query.yml"
sess, err := Init(to.Ptr(widget.settings.Queryfile))
if err != nil {
    log.Fatalf("azure init: %v", err)
}
Defensive patterns

Strategy: validation

Validate before calling

qf := widget.settings.Queryfile
if qf == "" {
    return errors.New("azurelogs: queryfile not configured")
}
if _, err := os.Stat(qf); err != nil {
    return fmt.Errorf("queryfile %q: %w", qf, err)
}

Try / catch

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

Prevention

When it happens

Trigger: Init(to.Ptr(widget.settings.Queryfile)) returns an error when the widget renders — e.g. the queryfile setting points to a nonexistent/invalid file, or Azure authentication setup inside Init fails (credentials not configured).

Common situations: Wtfutil config missing the azurelogs queryfile setting; invalid YAML/JSON query file; no az login or service-principal env vars in the environment where the dashboard runs.

Related errors


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

Appendix: source

Thrown at modules/azurelogs/widget.go:66

	if widget.Disabled() {
		return
	}

	// Reset state to allow fresh data fetch
	widget.loading = false
	widget.lastError = nil
	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

View on GitHub (pinned to bb838c1ccb)