mikefarah/yq · error

%v cannot be divided by %v

Error message

%v cannot be divided by %v

What it means

divideScalars reached its final else: the left/right scalar tag pair is not one of the supported numeric or string/string combinations. Division is only defined for int/int, int/float, float/float (and string splitting handled elsewhere), so pairs like !!str / !!int end here with both tags printed.

Source

Thrown at pkg/yqlib/operator_divide.go:68

		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
		}
		quotient := lhsNum / rhsNum
		if lhsIsCustom {
			target.Tag = lhs.Tag
		} else {
			target.Tag = "!!float"
		}
		target.Value = fmt.Sprintf("%v", quotient)
	} else {
		return fmt.Errorf("%v cannot be divided by %v", lhsTag, rhsTag)
	}
	return nil
}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Cast operands with tonumber before dividing
  2. For splitting a string, use the string/string form: "a,b" / ","
  3. Check that the data does not contain nulls or booleans where numbers were expected
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/yqlib/operator_divide.go:68 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/7586e9b9da52090e. Report an issue: GitHub.