alibaba/open-code-review · error
invalid config: %w
Error message
invalid config: %w
What it means
After loading the default template (and applying any maxTools override), loadCommonContext runs tpl.Validate(); a failure is wrapped as 'invalid config'. This means the task template struct itself is inconsistent — invalid limits, missing required fields — i.e. the effective configuration cannot pass invariant checks.
Source
Thrown at cmd/opencodereview/shared.go:100
//
// requireGit=true fails fast when the directory is not a git repo (review
// path: diff concept requires git). requireGit=false allows non-git
// directories (scan path: provider falls back to filepath.Walk).
//
// contentRef is the git ref whose file content the rule resolver should
// inspect when disambiguating ambiguous extensions — derive it via
// tool.ParseReviewMode(from, to, commit).RefValue(to, commit). Pass "" to
// read the working tree, which is what scan wants.
func loadCommonContext(repoDirInput, rulePath, contentRef string, maxTools, maxGitProcs int, requireGit bool) (*commonContext, error) {
tpl, err := template.LoadDefault()
if err != nil {
return nil, fmt.Errorf("load default template: %w", err)
}
if maxTools > tpl.MaxToolRequestTimes {
tpl.MaxToolRequestTimes = maxTools
}
if err := tpl.Validate(); err != nil {
return nil, fmt.Errorf("invalid config: %w", err)
}
repoDir, isGit, err := resolveWorkingDir(repoDirInput, requireGit)
if err != nil {
return nil, err
}
// Built before the resolver: the sniffer reads file content at contentRef
// through this limiter.
gitRunner := gitcmd.New(maxGitProcs)
resolver, fileFilter, err := rules.NewResolver(repoDir, rulePath, rules.ResolverOptions{
Ref: contentRef,
Runner: gitRunner,
})
if err != nil {
return nil, fmt.Errorf("load rules: %w", err)
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Rebuild from a clean tree so the embedded template is pristine
- Check what Validate() reports (unwrap the %w) and fix the offending field (e.g. non-positive limits)
- In tests, populate all required template fields before calling paths that validate it
Example fix
// before
tpl := &template.Template{} // empty -> invalid config
// after
tpl := template.Default(); tpl.MaxToolRequestTimes = maxTools // then Validate() Defensive patterns
Strategy: validation
Validate before calling
// validate any template you construct or override
if err := tpl.Validate(); err != nil {
return fmt.Errorf("template invalid before use: %w", err)
} Try / catch
if err := tpl.Validate(); err != nil {
return nil, fmt.Errorf("invalid config: %w", err)
} Prevention
- Never hand-edit embedded template defaults; use supported flags/overrides
- Call Validate() immediately after constructing or mutating a template in tests
- Keep template invariants (positive limits) documented for contributors
When it happens
Trigger: Commands built on loadCommonContext when the embedded template (possibly mutated by a maxTools override) fails Validate(), or in tests injecting a template with invalid field values.
Common situations: Local builds with hand-edited template defaults; tests constructing CommonContext/preview with zero or negative limits; maxTools override interacting badly with a template that has invalid other fields.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- max_tokens must be positive
- max_tool_request_times must be positive
- main_task.messages must not be empty
- load scan template: %w
- invalid scan template: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/9af8e036ed06c92b.
Report an issue: GitHub.