{"record":{"id":"58e16ae6b0680517","repo":"alibaba/open-code-review","slug":"load-tools-w","errorCode":null,"errorMessage":"load tools: %w","messagePattern":"load tools: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared.go","lineNumber":216,"sourceCode":"\tRuntimeConfig agent.RuntimeConfig\n}\n\n// newRetryCollector builds the per-run retry collector. It is a variable so a\n// test can hand back a collector whose invariants are already violated, which is\n// the only way to exercise the Freeze construction-error branch from the\n// outside: every production path finalizes every logical request on every exit,\n// so a well-behaved run can never produce one.\nvar newRetryCollector = llm.NewRetryCollector\n\n// loadLLMRuntime loads tool defs from toolConfigPath, reads the app config\n// from the user's default config path (applying the configured language to\n// tpl — defaulting when the config file is absent), resolves the LLM\n// endpoint (honoring resolveOpts), and\n// returns the runtime bundle. tpl is mutated in place.\nfunc loadLLMRuntime(tpl *template.Template, toolConfigPath string, resolveOpts llm.ResolveOptions) (*llmRuntime, error) {\n\ttoolEntries, err := toolsconfig.Load(toolConfigPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load tools: %w\", err)\n\t}\n\tplanToolDefs := agent.BuildToolDefs(toolEntries, true)\n\tmainToolDefs := agent.BuildToolDefs(toolEntries, false)\n\n\tcfgPath, err := defaultConfigPath()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tappCfg, err := LoadAppConfig(cfgPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load app config: %w\", err)\n\t}\n\t// Apply the language directive even when the config file is missing\n\t// (upstream #fix: ApplyLanguage with empty lang falls back to default).\n\tvar lang string\n\tif appCfg != nil {\n\t\tlang = appCfg.Language\n\t}","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared.go#L198-L234","documentation":"loadLLMRuntime loads the tool configuration via toolsconfig.Load and wraps any failure as `load tools: %w`. The tool config defines which agent tools are exposed to the LLM; a malformed, missing-but-required, or unreadable tool config aborts startup before any LLM call.","triggerScenarios":"ocr review/scan/executeReviewContext starting with toolConfigPath pointing to a file that does not parse (bad YAML/JSON schema), has invalid tool entries, or cannot be read (permissions).","commonSituations":"Hand-edited tools config with a schema typo; upgrade changed the config format; file created by root and unreadable by the running user; wrong path passed programmatically in tests.","solutions":["Open the path from the error and fix YAML/JSON syntax and field names to match the toolsconfig schema","Validate against the schema of the installed ocr version (config format can change between versions)","Fix file permissions (chmod/chown) so the running user can read it","Restore a known-good default tool config"],"exampleFix":"// before (tools.yaml)\ntools:\n  - name: read_file\n    comand: cat   # typo\n// after\ntools:\n  - name: read_file\n    command: cat","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(toolConfigPath); err != nil {\n\treturn fmt.Errorf(\"tool config unreadable: %w\", err)\n}\n// parse it yourself to surface syntax errors before ocr runs","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tlog.Fatalf(\"tool config invalid: %v — fix the file reported in the wrapped error\", err)\n}","preventionTips":["Keep tool config under version control with syntax CI checks","Re-validate configs after upgrading ocr (schema may change)","Avoid editing configs as root; keep them user-readable"],"tags":["go","config","startup"],"backgroundTag":"config-load-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}