{"record":{"id":"450b6c57f7dd104b","repo":"alibaba/open-code-review","slug":"preview-failed-w-450b6c","errorCode":null,"errorMessage":"preview failed: %w","messagePattern":"preview failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/review_cmd.go","lineNumber":498,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"%s value %q is not a valid commit ref: %s\", item.flag, item.ref, msg)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"%s value %q is not a valid commit ref\", item.flag, item.ref)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc runPreviewContext(ctx context.Context, cc *commonContext, opts reviewOptions, out io.Writer) error {\n\tpreview, err := agent.Preview(ctx, agent.Args{\n\t\tRepoDir:    cc.RepoDir,\n\t\tFrom:       opts.from,\n\t\tTo:         opts.to,\n\t\tCommit:     opts.commit,\n\t\tFileFilter: cc.FileFilter,\n\t\tGitRunner:  cc.GitRunner,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"preview failed: %w\", err)\n\t}\n\n\treturn outputPreview(preview, opts.outputFormat, out)\n}\n\nfunc initMCPClients(ctx context.Context, cfg *Config, tools *tool.Registry, repoDir, version string) []*mcp.Client {\n\tif cfg == nil || len(cfg.MCPServers) == 0 {\n\t\treturn nil\n\t}\n\n\tmcpNames := make([]string, 0, len(cfg.MCPServers))\n\tfor name := range cfg.MCPServers {\n\t\tmcpNames = append(mcpNames, name)\n\t}\n\tsort.Strings(mcpNames)\n\n\tvar clients []*mcp.Client\n\tfor _, name := range mcpNames {","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/review_cmd.go#L480-L516","documentation":"runPreviewContext calls agent.Preview to compute the diff/file set that would be reviewed. Any failure inside Preview (git diff errors, invalid refs, filter problems) is wrapped as \"preview failed\". The preview never renders; the underlying cause carries the real diagnosis.","triggerScenarios":"`ocr review --preview` (or runPreview) with refs that don't resolve, an empty diff context, git errors, or a failing custom GitRunner.","commonSituations":"--from/--to pointing at non-existent refs; previewing in a non-git directory that slipped past earlier checks; pathological file filters matching nothing combined with ref errors.","solutions":["Check the wrapped %w cause — fix the git/ref issue it names.","Verify both refs with `git rev-parse --verify <ref>^{commit}` before previewing.","Run with a plain range (e.g. --from origin/main --to HEAD) to isolate which ref is bad."],"exampleFix":"// before\nocr review --preview --from v1 --to v2   # v1 not a commit\n// after\ngit rev-parse --verify v1^{commit} && ocr review --preview --from v1 --to v2","handlingStrategy":"try-catch","validationCode":"for _, r := range []string{from, to, commit} {\n    if r == \"\" { continue }\n    if err := exec.Command(\"git\", \"rev-parse\", \"--verify\", r+\"^{commit}\").Run(); err != nil {\n        return fmt.Errorf(\"preview ref %q invalid\", r)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runPreviewContext(ctx, cc, opts, out); err != nil {\n    var perr *PreviewError\n    if errors.As(err, &perr) { /* inspect wrapped git cause */ }\n    return fmt.Errorf(\"preview: %w\", err)\n}","preventionTips":["Preview after fetching the refs involved.","Test the range with `git log --oneline from..to` first.","Keep the GitRunner healthy in test environments (mocks must return output)."],"tags":["git","preview","diff"],"backgroundTag":"preview-diff-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}