{"record":{"id":"2ee0438dfe962305","repo":"cilium/cilium","slug":"s-2f","errorCode":null,"errorMessage":"%s: %.2f%%","messagePattern":"(.+?): %\\.2f%%","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/complexity-diff/main.go","lineNumber":271,"sourceCode":"}\n\nfunc colorRelativeChange(program string, i int, p float64) (string, error) {\n\ts := fmt.Sprintf(\"%+d (%.2f\\\\\\\\%%) for %s\", i, p, program)\n\tif p == 0 {\n\t\treturn texNoColor(s), nil\n\t}\n\n\tif p < 0 {\n\t\treturn texGreen(s), nil\n\t}\n\n\treturn texRed(s), nil\n}\n\nfunc colorAbsoluteValue(program string, i int, p float64) (string, error) {\n\ts := fmt.Sprintf(\"%d (%.2f\\\\\\\\%%) for %s\", i, p, program)\n\tif p > ErrorThresholdLinearMetrics {\n\t\treturn texRed(s), fmt.Errorf(\"%s: %.2f%%\", program, p)\n\t}\n\tif p > WarningThresholdLinearMetrics {\n\t\treturn texOrange(s), nil\n\t}\n\n\treturn texNoColor(s), nil\n}\n\nfunc colorAbsoluteValueExponential(program string, i int, p float64) (string, error) {\n\ts := fmt.Sprintf(\"%d (%.2f\\\\\\\\%%) for %s\", i, p, program)\n\tif p > ErrorThresholdExponentialMetrics {\n\t\treturn texRed(s), fmt.Errorf(\"%s: %.2f%%\", program, p)\n\t}\n\tif p > WarningThresholdExponentialMetrics {\n\t\treturn texOrange(s), nil\n\t}\n\n\treturn texNoColor(s), nil","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/tools/complexity-diff/main.go#L253-L289","documentation":"colorAbsoluteValue in tools/complexity-diff formats a complexity metric for a program and returns an error when the percentage p exceeds ErrorThresholdLinearMetrics. The message '%s: %.2f%%' embeds the program name and the offending percentage. It signals that a linear complexity delta crossed the hard error threshold, failing the CI complexity-diff check.","triggerScenarios":"fmt.Errorf(\"%s: %.2f%%\", program, p) fires only when p > ErrorThresholdLinearMetrics inside colorAbsoluteValue, i.e. the computed absolute percentage change for a function in the compared program exceeds the error threshold for linear metrics.","commonSituations":"A code change adds significant cyclomatic complexity to a function in one of the analyzed programs; CI runs complexity-diff against a baseline and the absolute increase crosses the configured error cutoff.","solutions":["Reduce the complexity of the flagged function in the changed code (split it into smaller functions, remove branches).","Re-baseline the complexity snapshot if the increase is intentional and accepted by the team.","Adjust ErrorThresholdLinearMetrics in tools/complexity-diff/main.go if the current cutoff is too strict for the project."],"exampleFix":"// before\nif p > ErrorThresholdLinearMetrics {\n\treturn texRed(s), fmt.Errorf(\"%s: %.2f%%\", program, p)\n}\n// after\n// refactor the hot function, e.g.:\n// func process(input) { ... 20 branches ... }\n// becomes processValidate(input), processTransform(input), processCommit(input)\n// so the reported percentage drops below the threshold","handlingStrategy":"validation","validationCode":"if p > ErrorThresholdLinearMetrics {\n\tfmt.Printf(\"complexity gate will fail: %s at %.2f%%\\n\", program, p)\n\tos.Exit(1)\n}","typeGuard":null,"tryCatchPattern":"s, err := colorAbsoluteValue(prog, i, p)\nif err != nil {\n\tvar thErr *ThresholdError\n\tif errors.As(err, &thErr) {\n\t\tfmt.Fprintf(os.Stderr, \"complexity threshold exceeded: %v\\n\", err)\n\t}\n\treturn err\n}","preventionTips":["Run complexity-diff locally against the base branch before pushing.","Keep functions small; refactor when complexity warnings (orange) start appearing.","Keep the threshold config reviewed and documented in the repo.","Review the diff report in CI immediately and address red entries before merge."],"tags":["ci","complexity","threshold"],"backgroundTag":"complexity-threshold-exceeded","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}