{"record":{"id":"19e60ff6479001e8","repo":"alibaba/open-code-review","slug":"load-default-template-w","errorCode":null,"errorMessage":"load default template: %w","messagePattern":"load default template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared.go","lineNumber":94,"sourceCode":"\n// loadCommonContext validates the working directory, loads the embedded\n// template, raises MaxToolRequestTimes when maxTools exceeds the default,\n// resolves the absolute repo path, loads system review rules, and creates\n// the global git subprocess limiter. Both review and scan callers go\n// through this so the startup sequence stays consistent.\n//\n// requireGit=true fails fast when the directory is not a git repo (review\n// path: diff concept requires git). requireGit=false allows non-git\n// directories (scan path: provider falls back to filepath.Walk).\n//\n// contentRef is the git ref whose file content the rule resolver should\n// inspect when disambiguating ambiguous extensions — derive it via\n// tool.ParseReviewMode(from, to, commit).RefValue(to, commit). Pass \"\" to\n// read the working tree, which is what scan wants.\nfunc loadCommonContext(repoDirInput, rulePath, contentRef string, maxTools, maxGitProcs int, requireGit bool) (*commonContext, error) {\n\ttpl, err := template.LoadDefault()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load default template: %w\", err)\n\t}\n\tif maxTools > tpl.MaxToolRequestTimes {\n\t\ttpl.MaxToolRequestTimes = maxTools\n\t}\n\tif err := tpl.Validate(); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid config: %w\", err)\n\t}\n\n\trepoDir, isGit, err := resolveWorkingDir(repoDirInput, requireGit)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Built before the resolver: the sniffer reads file content at contentRef\n\t// through this limiter.\n\tgitRunner := gitcmd.New(maxGitProcs)\n\n\tresolver, fileFilter, err := rules.NewResolver(repoDir, rulePath, rules.ResolverOptions{","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared.go#L76-L112","documentation":"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.","triggerScenarios":"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).","commonSituations":"Broken or partial binary installation; a custom build with modified/removed embedded template assets; filesystem errors reading embedded resources (exotic builds).","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"],"exampleFix":"// before\ngo build ./cmd/opencodereview   # template assets deleted locally -> load default template: ...\n// after\ngit checkout -- internal/template/assets && make build","handlingStrategy":"retry","validationCode":"// sanity-check the embedded template early in your own bootstrap\ntpl, err := template.LoadDefault()\nif err != nil { return fmt.Errorf(\"install broken: %w\", err) }","typeGuard":null,"tryCatchPattern":"tpl, err := template.LoadDefault()\nif err != nil {\n    return fmt.Errorf(\"load default template: %w\", err) // reinstall if persistent\n}","preventionTips":["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"],"tags":["go","template","initialization"],"backgroundTag":"template-load-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}