{"record":{"id":"2c815175c15c090a","repo":"mikefarah/yq","slug":"could-not-find-v-for-format-time","errorCode":null,"errorMessage":"could not find %v for format_time","messagePattern":"could not find (.+?) for format_time","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_datetime.go","lineNumber":17,"sourceCode":"package yqlib\n\nimport (\n\t\"container/list\"\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"time\"\n)\n\nfunc getStringParameter(parameterName string, d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (string, error) {\n\tresult, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode)\n\n\tif err != nil {\n\t\treturn \"\", err\n\t} else if result.MatchingNodes.Len() == 0 {\n\t\treturn \"\", fmt.Errorf(\"could not find %v for format_time\", parameterName)\n\t}\n\n\treturn result.MatchingNodes.Front().Value.(*CandidateNode).Value, nil\n}\n\nfunc withDateTimeFormat(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tif expressionNode.RHS.Operation.OperationType == blockOpType || expressionNode.RHS.Operation.OperationType == unionOpType {\n\t\tlayout, err := getStringParameter(\"layout\", d, context, expressionNode.RHS.LHS)\n\t\tif err != nil {\n\t\t\treturn Context{}, fmt.Errorf(\"could not get date time format: %w\", err)\n\t\t}\n\t\tcontext.SetDateTimeLayout(layout)\n\t\treturn d.GetMatchingNodes(context, expressionNode.RHS.RHS)\n\n\t}\n\treturn Context{}, errors.New(`must provide a date time format string and an expression, e.g. with_dtf(\"Monday, 02-Jan-06 at 3:04PM MST\"; <exp>)`)\n\n}","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_datetime.go#L1-L35","documentation":"`getStringParameter` evaluates the expression that should supply a string parameter (layout, format, or timezone) for the datetime operators. If evaluating the argument expression yields zero matching nodes, it cannot extract a string and returns this error. The message always says 'format_time' regardless of which operator called it (a known message quirk).","triggerScenarios":"Calling `with_dtf(<empty>; ...)`, `format_time(<empty>)`, or `tz(<empty>)` where the argument expression selects nothing — e.g. a missing key like `.missing_key`, a `select()` that matches no nodes, or `// \"\"`-style fallbacks that produce empty results, or passing `empty` as the argument.","commonSituations":"Typo'd variable/field name inside the format argument (`$fmt` undefined, `.format` missing from the input), conditional defaults that evaluate to empty, or building expressions programmatically where the RHS slot is empty.","solutions":["Check that the argument expression actually resolves: run it standalone (`yq '.format' file.yml`) and ensure it prints a value","Provide a literal string instead of an expression: `with_dtf(\"2006-01-02\"; .)` or `format_time(\"Monday, 02 Jan 2006\")`","If the value may be missing, guard with a default that is a concrete string: `format_time(.format // \"2006-01-02\")`","Fix typos in variable references (`$fmt` vs `$format`) — undefined variables yield empty node sets"],"exampleFix":"// before: .fmt missing in input -> empty result\nyq 'with_dtf(.fmt; .date | format_time(\"2006-01-02\"))' file.yml\n// after: concrete or defaulted layout\nyq 'with_dtf(.fmt // \"2006-01-02\"; .date | format_time(\"2006-01-02\"))' file.yml","handlingStrategy":"validation","validationCode":"# verify the argument resolves to a value before running the operator\nyq '(.format // \"2006-01-02\") | type' file.yml   # must print !!str\n# or test the inner expression standalone first","typeGuard":null,"tryCatchPattern":"// wrap yq run; on this error, retry with a literal default layout\nif out, err := run(\"yq\", expr, file); err != nil &&\n\tstrings.Contains(out, \"could not find\") {\n\tout, err = run(\"yq\", withLiteralLayout(expr), file)\n}","preventionTips":["Pass literal strings for layout/format/timezone instead of document lookups when possible","Always provide `//` defaults for expression-supplied parameters","Test the parameter expression standalone before embedding it in with_dtf/format_time","Watch for undefined variables ($name) that silently produce empty results"],"tags":["yq","datetime","missing-argument"],"backgroundTag":"missing-expression-argument","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}