wtfutil/wtf · error

failed to parse YAML in config file %s: %w

Error message

failed to parse YAML in config file %s: %w

What it means

This error is returned by readQueryFileContent in modules/azurelogs/config.go:53 when yaml.Unmarshal fails to parse the contents of the query config file into the config struct. It wraps the underlying YAML error, so the wrapped message pinpoints the offending line/column. The library throws it because a malformed YAML file cannot be safely turned into a Session QueryFile.

Source

Thrown at modules/azurelogs/config.go:53

		sess.QueryFile = configFile
	} else {
		return fmt.Errorf("invalid query file format: %s, expected .yaml", filename)
	}

	return nil
}

// readQueryFileContent reads a single config file and returns a QueryFile struct
func readQueryFileContent(filePath string) (QueryFile, error) {
	var configFile QueryFile
	data, err := os.ReadFile(filePath)
	if err != nil {
		return configFile, fmt.Errorf("failed to read query config file %s: %w", filePath, err)
	}

	err = yaml.Unmarshal(data, &configFile)
	if err != nil {
		return configFile, fmt.Errorf("failed to parse YAML in config file %s: %w", filePath, err)
	}

	return configFile, nil
}

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Open the file at the path named in the error and fix the YAML syntax at the line/column reported by the wrapped error
  2. Validate the file with a YAML linter (e.g. yamllint or `python -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" <file>`)
  3. Replace tab characters with spaces for indentation
  4. Quote values containing special characters like ':' or '#'

Example fix

// before (config.yml)
workspace:
	id: my-workspace  # tab indentation breaks YAML parser
// after
workspace:
  id: "my-workspace"  # spaces, quoted value
Defensive patterns

Strategy: validation

Validate before calling

data, err := os.ReadFile(queryPath)
if err != nil { return err }
var probe map[string]any
if err := yaml.Unmarshal(data, &probe); err != nil {
    return fmt.Errorf("invalid YAML in %s: %w", queryPath, err)
}

Try / catch

sess, err := azurelogs.Init(&queryPath)
if err != nil {
    var yamlErr error
    if errors.Unwrap(err) != nil { /* inspect wrapped cause */ }
    log.Fatalf("query config invalid: %v", err)
}

Prevention

When it happens

Trigger: Calling Init/readQueryFile with a query file whose content is not valid YAML: bad indentation, tabs instead of spaces, missing colon after a key, duplicate keys, or YAML special characters unquoted. Also produced by yaml tags in the file not matching the struct (caught by TestQueryFile_YAMLTags).

Common situations: Hand-edited query config files with wrong indentation (tabs are illegal in YAML), copy-pasted config losing indentation, unquoted values containing ':' or '#', or a query path pointing to a JSON/other non-YAML file.

Understand the failure class

Related errors


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