mikefarah/yq · error
filename expression returned nil
Error message
filename expression returned nil
What it means
loadString evaluates its RHS expression to obtain a filename; the evaluation succeeded but produced zero matching nodes (front() == nil). There is no filename to open — typically the filename expression selected a missing field or filtered everything out.
Source
Thrown at pkg/yqlib/operator_load.go:80
}
func loadStringOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("loadString")
if ConfiguredSecurityPreferences.DisableFileOps {
return Context{}, fmt.Errorf("file operations have been disabled")
}
var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
rhs, err := d.GetMatchingNodes(context.SingleReadonlyChildContext(candidate), expressionNode.RHS)
if err != nil {
return Context{}, err
}
if rhs.MatchingNodes.Front() == nil {
return Context{}, fmt.Errorf("filename expression returned nil")
}
nameCandidateNode := rhs.MatchingNodes.Front().Value.(*CandidateNode)
filename := nameCandidateNode.Value
contentsCandidate, err := loadString(filename)
if err != nil {
return Context{}, fmt.Errorf("failed to load %v: %w", filename, err)
}
results.PushBack(contentsCandidate)
}
return context.ChildContext(results), nil
}
func loadOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {View on GitHub (pinned to 8b5af0694b)
Solutions
- Make the filename expression always yield a string, e.g. "file.yaml" as a literal
- Check that the field holding the filename exists: .filename // "default.yaml"
- Avoid select() filters that can return nothing on the RHS of load
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/yqlib/operator_load.go:80 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/7abb2194c86eef91.
Report an issue: GitHub.