{"record":{"id":"145381cd9e970237","repo":"shadow1ng/fscan","slug":"webscan-expression-compile-failed","errorCode":"webscan_expression_compile_failed","errorMessage":"webscan_expression_compile_failed: %w","messagePattern":"webscan_expression_compile_failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"webscan/lib/Eval.go","lineNumber":168,"sourceCode":"\n// EvaluateCached 评估 CEL 表达式（带编译缓存，用于规则执行热路径）\nfunc EvaluateCached(env *cel.Env, expression string, params map[string]interface{}, cache CelProgCache) (ref.Val, error) {\n\tif expression == \"\" {\n\t\treturn types.Bool(true), nil\n\t}\n\n\tvar program cel.Program\n\n\tif cache != nil {\n\t\tif cached, ok := cache[expression]; ok {\n\t\t\tprogram = cached\n\t\t}\n\t}\n\n\tif program == nil {\n\t\tast, issues := env.Compile(expression)\n\t\tif issues.Err() != nil {\n\t\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"webscan_expression_compile_failed\"), issues.Err())\n\t\t}\n\n\t\tvar err error\n\t\tprogram, err = env.Program(ast, GetBaseProgramOptions()...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"webscan_program_create_failed\"), err)\n\t\t}\n\n\t\tif cache != nil {\n\t\t\tcache[expression] = program\n\t\t}\n\t}\n\n\tresult, _, err := program.Eval(params)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", i18n.GetText(\"webscan_expression_eval_failed\"), err)\n\t}\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/webscan/lib/Eval.go#L150-L186","documentation":"EvaluateCached compiles a CEL expression with env.Compile(); if the compiler reports issues (syntax errors, undeclared references, type errors) it wraps them under webscan_expression_compile_failed. The expression text is invalid for the declared CEL environment.","triggerScenarios":"Evaluate(expression, params) / EvaluateCached with an expression containing CEL syntax errors, unknown function names, undeclared variables, or type-incompatible operations for the base env plus POC declarations.","commonSituations":"POC expressions with Go-style operators CEL doesn't support (&& with mismatched types, == between different types), typos in variable names like respone instead of response, use of functions not registered in the env, quoting problems producing empty or garbled expressions.","solutions":["Read issues.Err() — CEL reports the exact line/offset and reason","Check every identifier in the expression is declared (request/response variables for POCs)","Fix CEL syntax: use contains(), size(), matches() instead of Go/JS idioms","Test the expression in a CEL playground before adding it to the POC","Ensure custom functions used are registered via GetBaseProgramOptions/env options"],"exampleFix":"// before (undeclared variable typo)\nEvaluate(\"respone.status == 200\", params)\n// after\nEvaluate(\"response.status == 200\", params)","handlingStrategy":"validation","validationCode":"func validCEL(env *cel.Env, expr string) error {\n    ast, issues := env.Compile(expr)\n    return issues.Err()\n}","typeGuard":null,"tryCatchPattern":"result, err := Evaluate(expr, params)\nif err != nil {\n    var ce *cel.Issues\n    log.Printf(\"expression %q failed to compile: %v\", expr, err)\n    return fmt.Errorf(\"bad poc expression %q: %w\", expr, err)\n}","preventionTips":["Compile-check all POC expressions at load time, not at scan time","Only use identifiers declared in the env (request/response fields)","Prefer CEL builtins: contains(), matches(), size(), has()"],"tags":["go","cel","expression","compile","webscan"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}