mikefarah/yq · error

from_unix only works on numbers, found %v instead

Error message

from_unix only works on numbers, found %v instead

What it means

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.

Source

Thrown at pkg/yqlib/operator_datetime.go:147

	if err != nil {
		return time.Now(), err
	}

	return time.UnixMilli(int64(seconds * 1000)), nil
}

func fromUnixOp(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {

	var results = list.New()

	for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
		candidate := el.Value.(*CandidateNode)

		actualTag := candidate.guessTagFromCustomType()

		if actualTag != "!!int" && actualTag != "!!float" {
			return Context{}, fmt.Errorf("from_unix only works on numbers, found %v instead", candidate.Tag)
		}

		parsedTime, err := parseUnixTime(candidate.Value)
		if err != nil {
			return Context{}, err
		}

		node := candidate.CreateReplacement(ScalarNode, "!!timestamp", parsedTime.Format(time.RFC3339))

		results.PushBack(node)
	}

	return context.ChildContext(results), nil
}

func toUnixOp(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {

	layout := context.GetDateTimeLayout()

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Convert the value to a number first: . | tonumber | from_unix
  2. Select only the timestamp field, not its parent map
  3. If the timestamp is a string like "1700000000", cast it with tonumber
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/yqlib/operator_datetime.go:147 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/47e42bd519456716. Report an issue: GitHub.