{"record":{"id":"47e42bd519456716","repo":"mikefarah/yq","slug":"from-unix-only-works-on-numbers-found-v-instead","errorCode":null,"errorMessage":"from_unix only works on numbers, found %v instead","messagePattern":"from_unix only works on numbers, found (.+?) instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_datetime.go","lineNumber":147,"sourceCode":"\n\tif err != nil {\n\t\treturn time.Now(), err\n\t}\n\n\treturn time.UnixMilli(int64(seconds * 1000)), nil\n}\n\nfunc fromUnixOp(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {\n\n\tvar results = list.New()\n\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)\n\n\t\tactualTag := candidate.guessTagFromCustomType()\n\n\t\tif actualTag != \"!!int\" && actualTag != \"!!float\" {\n\t\t\treturn Context{}, fmt.Errorf(\"from_unix only works on numbers, found %v instead\", candidate.Tag)\n\t\t}\n\n\t\tparsedTime, err := parseUnixTime(candidate.Value)\n\t\tif err != nil {\n\t\t\treturn Context{}, err\n\t\t}\n\n\t\tnode := candidate.CreateReplacement(ScalarNode, \"!!timestamp\", parsedTime.Format(time.RFC3339))\n\n\t\tresults.PushBack(node)\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n\nfunc toUnixOp(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {\n\n\tlayout := context.GetDateTimeLayout()","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_datetime.go#L129-L165","documentation":"from_unix converts each matched node from a unix timestamp, which requires a number. The guard checks the node's resolved tag (custom types are unwrapped via guessTagFromCustomType) and rejects anything that is not !!int or !!float — e.g. running from_unix against a string timestamp or a map.","triggerScenarios":"Thrown at pkg/yqlib/operator_datetime.go:147 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the value to a number first: . | tonumber | from_unix","Select only the timestamp field, not its parent map","If the timestamp is a string like \"1700000000\", cast it with tonumber"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}