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
- Open the file at the path named in the error and fix the YAML syntax at the line/column reported by the wrapped error
- Validate the file with a YAML linter (e.g. yamllint or `python -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" <file>`)
- Replace tab characters with spaces for indentation
- 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
- Lint query YAML files in CI with yamllint before deployment
- Use spaces, never tabs, for YAML indentation
- Keep query files in version control so bad edits are caught in review
- Add a unit test that unmarshals every shipped query file at build time
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to read query file %s: %w
- cannot store secrets: wtf.secretStore is not configured
- client could not be initialized
- we didn't find the section %s
- azure workspace ID is required but not configured
AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03).
Data as JSON: /api/errors/22212f7045b13280.
Report an issue: GitHub.