mikefarah/yq · error

%v cannot modulo by %v

Error message

%v cannot modulo by %v

What it means

moduloScalars reached its final else: the left/right tag pair is not int/int or numeric/numeric (custom types are unwrapped first). Combinations like !!str % !!int, or mixing booleans/nulls with numbers, have no modulo semantics defined, so both tags are reported and the operation aborted.

Source

Thrown at pkg/yqlib/operator_modulo.go:83

		target.Style = lhs.Style

		lhsNum, err := strconv.ParseFloat(lhs.Value, 64)
		if err != nil {
			return err
		}
		rhsNum, err := strconv.ParseFloat(rhs.Value, 64)
		if err != nil {
			return err
		}
		remainder := math.Mod(lhsNum, rhsNum)
		if lhsIsCustom {
			target.Tag = lhs.Tag
		} else {
			target.Tag = "!!float"
		}
		target.Value = fmt.Sprintf("%v", remainder)
	} else {
		return fmt.Errorf("%v cannot modulo by %v", lhsTag, rhsTag)
	}
	return nil
}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Cast operands with tonumber before using %
  2. Ensure both operands are numeric (no strings, nulls or bools)
  3. Check the data for missing fields that default to null
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/yqlib/operator_modulo.go:83 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/244b7309a9818667. Report an issue: GitHub.