wtfutil/wtf · error

failed to read query file %s: %w

Error message

failed to read query file %s: %w

What it means

Init in modules/azurelogs/session.go:29 wraps any error from readQueryFile with this message, embedding the query file path. readQueryFile in turn can fail on file reads or YAML parsing (see error 40), so this is the outermost wrapper for all query-config loading problems. Authentication (line 24) has already succeeded when this fires.

Source

Thrown at modules/azurelogs/session.go:29

const (
	envAzureClientID     = "AZURE_CLIENT_ID"
	envAzureClientSecret = "AZURE_CLIENT_SECRET"
	envAzureTenantID     = "AZURE_TENANT_ID"
)

// Init initializes a new Azure session with the specified query file
func Init(queryPath *string) (*Session, error) {
	sess := &Session{}
	sess.Azure = &AZSession{}

	// Initialize Azure authentication using modern non-deprecated libraries
	if err := InitializeAzureAuthentication(sess); err != nil {
		return nil, fmt.Errorf("failed to initialize Azure authentication: %w", err)
	}

	err := readQueryFile(sess, *queryPath)
	if err != nil {
		return nil, fmt.Errorf("failed to read query file %s: %w", *queryPath, err)
	}

	return sess, nil
}

// Session holds the configuration and state for an Azure Log Analytics session
type Session struct {
	App struct {
		SemVer string
	}

	Azure       *AZSession
	QueriesPath string
	QueryFile   QueryFile
}

// AZClientSecretCredential holds Azure service principal credentials
type AZClientSecretCredential struct {

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Verify the path passed to Init exists: `ls -la <path>` (use an absolute path or correct the working directory)
  2. Check file read permissions for the user running the process
  3. If the wrapped error mentions YAML parsing, fix the YAML syntax in the file (see error 40)
  4. In containers, confirm the query file is copied/mounted into the image at the expected path

Example fix

// before
sess, err := azurelogs.Init(ptr.To("queries.yml"))  // wrong CWD, file not found
// after
sess, err := azurelogs.Init(ptr.To("/etc/azurelogs/queries.yml"))  // absolute path
Defensive patterns

Strategy: validation

Validate before calling

func validateQueryPath(p string) error {
    info, err := os.Stat(p)
    if err != nil {
        return fmt.Errorf("query file not accessible at %s: %w", p, err)
    }
    if info.IsDir() {
        return fmt.Errorf("%s is a directory, expected a YAML file", p)
    }
    return nil
}

Try / catch

if err := validateQueryPath(queryPath); err == nil {
    sess, err = azurelogs.Init(&queryPath)
}
if err != nil {
    if strings.Contains(err.Error(), "failed to read query file") {
        return fmt.Errorf("check path/permissions/YAML for %s: %w", queryPath, err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Init(queryPath) where the query file does not exist, is unreadable (permissions), is a directory, or contains invalid YAML — any non-nil error returned by readQueryFile.

Common situations: Typo'd or relative path resolved from the wrong working directory, file not mounted into a container, permissions changed by deployment, or malformed YAML as in error 40.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


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