{"record":{"id":"10337eb3681ab6c5","repo":"mikefarah/yq","slug":"v-v-cannot-modulo-by-v-v","errorCode":null,"errorMessage":"%v (%v) cannot modulo by %v (%v)","messagePattern":"(.+?) \\((.+?)\\) cannot modulo by (.+?) \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_modulo.go","lineNumber":18,"sourceCode":"package yqlib\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc moduloOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"Modulo operator\")\n\n\treturn crossFunction(d, context.ReadOnlyClone(), expressionNode, modulo, false)\n}\n\nfunc modulo(_ *dataTreeNavigator, _ Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {\n\tif lhs.Tag == \"!!null\" {\n\t\treturn nil, fmt.Errorf(\"%v (%v) cannot modulo 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 := moduloScalars(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 modulo by %v (%v)\", lhs.Tag, lhs.GetNicePath(), rhs.Tag, rhs.GetNicePath())\n\t}\n\n\treturn target, nil\n}\n\nfunc moduloScalars(target *CandidateNode, lhs *CandidateNode, rhs *CandidateNode) error {\n\tlhsTag := lhs.Tag\n\trhsTag := rhs.guessTagFromCustomType()","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_modulo.go#L1-L36","documentation":"The modulo operator short-circuits when the left-hand tag is !!null, mirroring divide: 'null % n' is undefined, so it errors naming both operands and their paths. In practice the LHS expression matched a missing or null field.","triggerScenarios":"Thrown at pkg/yqlib/operator_modulo.go:18 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Guard the LHS: select(. != null) % 2","Provide a default: (.n // 0) % 2","Ensure the field exists in the input document"],"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"}