alibaba/open-code-review · error
load default template: %w
Error message
load default template: %w
What it means
loadCommonContext fails to load the embedded default task template via template.LoadDefault() and wraps the cause. The template is compiled into the binary, so failure usually means embedded resource extraction failed or the template data is corrupt/misversioned — rare and typically a build/install problem rather than user input.
Source
Thrown at cmd/opencodereview/shared.go:94
// loadCommonContext validates the working directory, loads the embedded
// template, raises MaxToolRequestTimes when maxTools exceeds the default,
// resolves the absolute repo path, loads system review rules, and creates
// the global git subprocess limiter. Both review and scan callers go
// through this so the startup sequence stays consistent.
//
// 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{View on GitHub (pinned to 5cf97d0d15)
Solutions
- Reinstall or rebuild ocr from a clean checkout (make build / go install from upstream)
- Verify the build includes intact embedded template assets (no local deletions under the templates directory)
- If reproducing, check the underlying error via %w (verbose output) to pinpoint the embedded FS failure
Example fix
// before go build ./cmd/opencodereview # template assets deleted locally -> load default template: ... // after git checkout -- internal/template/assets && make build
Defensive patterns
Strategy: retry
Validate before calling
// sanity-check the embedded template early in your own bootstrap
tpl, err := template.LoadDefault()
if err != nil { return fmt.Errorf("install broken: %w", err) } Try / catch
tpl, err := template.LoadDefault()
if err != nil {
return fmt.Errorf("load default template: %w", err) // reinstall if persistent
} Prevention
- Install ocr via the official release, not partial copies
- Rebuild with `make build` after touching embedded assets
- Fail fast at startup with the unwrapped cause for diagnosis
When it happens
Trigger: Any command going through loadCommonContext (review, manual review, delegate/scan paths) at startup when template.LoadDefault() returns an error (embedded FS read failure, corrupt embedded data).
Common situations: Broken or partial binary installation; a custom build with modified/removed embedded template assets; filesystem errors reading embedded resources (exotic builds).
Related errors
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/19e60ff6479001e8.
Report an issue: GitHub.