{"record":{"id":"9afc48dfb6fa7e08","repo":"shadow1ng/fscan","slug":"webscan-cel-env-not-initialized","errorCode":"webscan_cel_env_not_initialized","errorMessage":"webscan_cel_env_not_initialized","messagePattern":"webscan_cel_env_not_initialized","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"webscan/lib/Eval.go","lineNumber":118,"sourceCode":"}\n\n// GetBaseEnv 获取基础CEL环境\nfunc GetBaseEnv() *cel.Env {\n\tinitBaseEnv()\n\treturn baseEnv\n}\n\n// GetBaseProgramOptions 获取基础程序选项\nfunc GetBaseProgramOptions() []cel.ProgramOption {\n\tinitBaseEnv()\n\treturn baseProgramOpt\n}\n\n// ExtendEnvWithVars 扩展基础环境，添加POC特定的变量声明\nfunc ExtendEnvWithVars(varDecls []*exprpb.Decl) (*cel.Env, error) {\n\tbase := GetBaseEnv()\n\tif base == nil {\n\t\treturn nil, fmt.Errorf(\"%s\", i18n.GetText(\"webscan_cel_env_not_initialized\"))\n\t}\n\tif len(varDecls) == 0 {\n\t\treturn base, nil\n\t}\n\t//nolint:staticcheck // SA1019: cel.Declarations已废弃但CEL库尚未提供替代方案\n\treturn base.Extend(cel.Declarations(varDecls...))\n}\n\n// MakeVarDecl 根据变量名和表达式创建变量声明\nfunc MakeVarDecl(key, value string) *exprpb.Decl {\n\tswitch {\n\tcase strings.HasPrefix(value, \"randomInt\"):\n\t\t//nolint:staticcheck // SA1019: decls.NewIdent已废弃但CEL库尚未提供替代方案\n\t\treturn decls.NewIdent(key, decls.Int, nil)\n\tcase strings.HasPrefix(value, \"newReverse\"):\n\t\t//nolint:staticcheck // SA1019: decls.NewIdent已废弃但CEL库尚未提供替代方案\n\t\treturn decls.NewIdent(key, decls.NewObjectType(\"lib.Reverse\"), nil)\n\tdefault:","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/webscan/lib/Eval.go#L100-L136","documentation":"ExtendEnvWithVars builds a CEL environment by extending the shared base env with POC-specific variable declarations. If GetBaseEnv() returns nil the base CEL environment was never initialized (cel.NewEnv at startup failed or init was skipped), so extension is impossible.","triggerScenarios":"Calling ExtendEnvWithVars(varDecls) (directly or via executePoc) before the base environment was created by the package's init/initialization path, or after base env construction failed and was swallowed earlier.","commonSituations":"Import-order issues where Eval setup is skipped, custom builds with modified init, base env init failing due to a bad custom function/declaration registered at startup, using the library in tests without invoking the initializer.","solutions":["Ensure the package's environment initialization runs before any evaluation (check init() in Eval.go or explicit InitEnv call)","Check startup logs for earlier base-env creation failures and fix the root cause","In tests, call the base env initializer before ExtendEnvWithVars","Verify no build tags exclude the initialization file"],"exampleFix":"// before (using eval before init)\nenv, err := ExtendEnvWithVars(decls)\n// after (ensure base env initialized first)\nif GetBaseEnv() == nil {\n    if err := InitBaseEnv(); err != nil { return err }\n}\nenv, err := ExtendEnvWithVars(decls)","handlingStrategy":"type-guard","validationCode":"if GetBaseEnv() == nil {\n    return errors.New(\"CEL base env not initialized; call InitBaseEnv first\")\n}","typeGuard":"func baseEnvReady() bool { return GetBaseEnv() != nil }","tryCatchPattern":"env, err := ExtendEnvWithVars(decls)\nif err != nil {\n    if err.Error() == i18n.GetText(\"webscan_cel_env_not_initialized\") {\n        return fmt.Errorf(\"library init skipped: %w\", err)\n    }\n    return err\n}","preventionTips":["Always run library initialization at process startup before evaluation","Assert GetBaseEnv() != nil in tests before exercising POC evaluation","Fail fast at boot if base env creation returns an error"],"tags":["go","cel","initialization","webscan","expression-engine"],"backgroundTag":"module-init-failed","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}