alibaba/open-code-review · error
load config: %w
Error message
load config: %w
What it means
This error wraps any failure from LoadAppConfig when running `ocr llm test`. The config file at the resolved path either cannot be read, does not exist in an expected state, or fails parsing/validation. The %w wrapper preserves the underlying cause (parse error, permission error, etc.) for inspection with errors.Is/As.
Source
Thrown at cmd/opencodereview/llm_cmd.go:61
Run: func(cmd *cobra.Command, args []string) {
runLLMProviders()
},
}
func init() {
llmCmd.AddCommand(llmTestCmd)
llmCmd.AddCommand(llmProvidersCmd)
}
func runLLMTest() error {
cfgPath, err := resolveConfigPath()
if err != nil {
return err
}
appCfg, err := LoadAppConfig(cfgPath)
if err != nil {
return fmt.Errorf("load config: %w", err)
}
ep, err := llm.ResolveEndpoint(cfgPath)
if err != nil {
return fmt.Errorf("resolve LLM endpoint: %w", err)
}
task, err := testconnection.LoadDefault()
if err != nil {
return fmt.Errorf("load test task config: %w", err)
}
var lang string
if appCfg != nil {
lang = appCfg.Language
}
task.ApplyLanguage(lang)
timeout := 30 * time.SecondView on GitHub (pinned to 5cf97d0d15)
Solutions
- Run `ocr config provider` (or check the resolved config path) and fix the file's syntax or missing fields.
- Regenerate a valid config: `ocr init` or re-save via the provider TUI.
- Verify the --config path exists and is readable: `ls -l <path>` and `cat <path>`.
- Read the wrapped cause after 'load config:' in the message — it names the exact parse/validation failure.
Example fix
// before (malformed config) [llm url = "https://api.example.com" // after (valid TOML) [llm] url = "https://api.example.com"
Defensive patterns
Strategy: validation
Validate before calling
cfgPath := "~/.ocr/config.toml"
if _, err := os.Stat(cfgPath); err != nil {
return fmt.Errorf("config file missing: %w", err)
}
if _, err := LoadAppConfig(cfgPath); err != nil {
return fmt.Errorf("config invalid, fix before running llm test: %w", err)
} Try / catch
if _, err := LoadAppConfig(cfgPath); err != nil {
var parseErr *os.PathError
if errors.As(err, &parseErr) { /* fix path/permissions */ }
return fmt.Errorf("load config: %w", err)
} Prevention
- Validate config files with a linter or `ocr llm test` after every hand edit.
- Never hand-edit config without backing it up first.
- Use `ocr config provider` TUI instead of manual edits to keep the schema valid.
When it happens
Trigger: Running `ocr llm test` when LoadAppConfig(cfgPath) returns an error: the config file is missing required fields, contains invalid TOML/JSON syntax, or cannot be read from disk (permissions, wrong --config path).
Common situations: Hand-edited config with a syntax typo; pointing at a non-existent config path via --config; a config written by an older binary that fails current schema validation; read-permission problems after switching users or CI environments.
Related errors
- MCP server %q not found
- custom provider %q not found
- read app config %s: %w
- invalid boolean for llm.use_anthropic: %w
- load scan template: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/d546dfdcb3714b0a.
Report an issue: GitHub.