mikefarah/yq · error

unable to parse duration [%v]: %w

Error message

unable to parse duration [%v]: %w

What it means

addDateTimes is adding a duration to a datetime (lhs), but time.ParseDuration rejected the right-hand scalar as a Go duration string. Valid durations look like '300ms', '-1.5h' or '2h45m' — a bare number, an ISO interval, or a misspelled unit fails here; the %w carries ParseDuration's own reason.

Source

Thrown at pkg/yqlib/operator_add.go:154

		}
		sum := lhsNum + rhsNum
		if lhsIsCustom {
			target.Tag = lhs.Tag
		} else {
			target.Tag = "!!float"
		}
		target.Value = fmt.Sprintf("%v", sum)
	} else {
		return fmt.Errorf("%v cannot be added to %v", lhsTag, rhsTag)
	}
	return nil
}

func addDateTimes(layout string, target *CandidateNode, lhs *CandidateNode, rhs *CandidateNode) error {

	duration, err := time.ParseDuration(rhs.Value)
	if err != nil {
		return fmt.Errorf("unable to parse duration [%v]: %w", rhs.Value, err)
	}

	currentTime, err := parseDateTime(layout, lhs.Value)
	if err != nil {
		return err
	}

	newTime := currentTime.Add(duration)
	target.Value = newTime.Format(layout)
	return nil

}

func addSequences(target *CandidateNode, lhs *CandidateNode, rhs *CandidateNode) {
	log.Debugf("adding sequences! target: %v; lhs %v; rhs: %v", NodeToString(target), NodeToString(lhs), NodeToString(rhs))
	target.Kind = SequenceNode
	if len(lhs.Content) == 0 {
		log.Debugf("dont copy lhs style")

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Use Go duration syntax with explicit units, e.g. "24h" or "30m"
  2. Do not use bare numbers — '5' is invalid, '5m' is valid
  3. Check for stray whitespace or invalid unit suffixes in the duration string
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/yqlib/operator_add.go:154 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05). Data as JSON: /api/errors/d54e915e3b30a2f8. Report an issue: GitHub.