{"record":{"id":"5f02a491c2838c45","repo":"mikefarah/yq","slug":"v-v-cannot-be-divided-by-v-v","errorCode":null,"errorMessage":"%v (%v) cannot be divided by %v (%v)","messagePattern":"(.+?) \\((.+?)\\) cannot be divided by (.+?) \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_divide.go","lineNumber":17,"sourceCode":"package yqlib\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc divideOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"Divide operator\")\n\n\treturn crossFunction(d, context.ReadOnlyClone(), expressionNode, divide, false)\n}\n\nfunc divide(_ *dataTreeNavigator, _ Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {\n\tif lhs.Tag == \"!!null\" {\n\t\treturn nil, fmt.Errorf(\"%v (%v) cannot be divided by %v (%v)\", lhs.Tag, lhs.GetNicePath(), rhs.Tag, rhs.GetNicePath())\n\t}\n\n\ttarget := lhs.CopyWithoutContent()\n\n\tif lhs.Kind == ScalarNode && rhs.Kind == ScalarNode {\n\t\tif err := divideScalars(target, lhs, rhs); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t} else {\n\t\treturn nil, fmt.Errorf(\"%v (%v) cannot be divided by %v (%v)\", lhs.Tag, lhs.GetNicePath(), rhs.Tag, rhs.GetNicePath())\n\t}\n\n\treturn target, nil\n}\n\nfunc divideScalars(target *CandidateNode, lhs *CandidateNode, rhs *CandidateNode) error {\n\tlhsTag := lhs.Tag\n\trhsTag := rhs.guessTagFromCustomType()","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_divide.go#L1-L35","documentation":"The divide operator short-circuits when the left-hand tag is !!null: dividing null by anything is undefined, so it errors naming both sides and their paths. This fires for expressions like null / 2 or when the LHS expression matched a missing/null field.","triggerScenarios":"Thrown at pkg/yqlib/operator_divide.go:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Guard for nulls: select(. != null) / 2 or use // alternative","Ensure the LHS field exists in the document before dividing","Provide a default: (.count // 0) / 2"],"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"}