{"record":{"id":"af740698ebd28ec0","repo":"kubernetes/kubernetes","slug":"running-apidiff-on-working-tree-w","errorCode":null,"errorMessage":"running apidiff on working tree: %w","messagePattern":"running apidiff on working tree: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hack/apidiff-changelog/main.go","lineNumber":147,"sourceCode":"\t\treturn fmt.Errorf(\"resolving repo root %q: %w\", opts.repoRoot, err)\n\t}\n\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting working directory: %w\", err)\n\t}\n\tdirs, err = normalizeDirs(cwd, repoRoot, dirs)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"normalizing directories: %w\", err)\n\t}\n\n\tafterDir := filepath.Join(tempDir, \"after\")\n\tbeforeDir := filepath.Join(tempDir, \"before\")\n\n\t// Dump API state for the target revision (or the working tree).\n\tif opts.target == \"\" {\n\t\tif err := runApidiff(repoRoot, dirs, afterDir); err != nil {\n\t\t\treturn fmt.Errorf(\"running apidiff on working tree: %w\", err)\n\t\t}\n\t} else {\n\t\ttargetWorktree := filepath.Join(tempDir, \"target\")\n\t\tcleanup, err := setupWorktree(targetWorktree, opts.target)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer cleanup()\n\t\tif err := runApidiff(targetWorktree, dirs, afterDir); err != nil {\n\t\t\treturn fmt.Errorf(\"running apidiff on target %s: %w\", opts.target, err)\n\t\t}\n\t}\n\n\t// Dump API state for the base revision.\n\tbaseWorktree := filepath.Join(tempDir, \"base\")\n\tcleanup, err := setupWorktree(baseWorktree, opts.base)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/b882c60b4023bdf09264c2d5d30a2cadebc240fb/hack/apidiff-changelog/main.go#L129-L165","documentation":"Returned from runDiff (main.go:147) wrapping a failure from runApidiff(repoRoot, dirs, afterDir) when --target is empty (i.e. comparing the working tree as the \"after\" state). runApidiff runs `apidiff -m -w <outfile> .` in each module dir concurrently and joins per-module errors; this wraps the joined result. The wrapped error includes apidiff's stderr per module.","triggerScenarios":"Any module's `apidiff -m -w` invocation fails: module does not build (compile errors), is not a Go module, has syntax errors, or apidiff itself crashes. Because the working tree is used, uncommitted broken code triggers it.","commonSituations":"Running the tool mid-refactor with uncompilable code in a module; module missing go.mod; apidiff version mismatch with the Go version; vendor directory out of sync; build constraints excluding all files.","solutions":["Read the wrapped per-module apidiff stderr to find which module failed.","Make sure each module compiles: `go build ./...` from the module dir.","Ensure each module has a go.mod at its root.","Run `go mod tidy` / vendor sync if the module is in the vendored tree, then retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Best-effort preflight: ensure each module compiles before running apidiff.\nfunc preflightBuild(repoRoot string, dirs []string) error {\n    for _, d := range dirs {\n        cmd := exec.Command(\"go\", \"build\", \"./...\")\n        cmd.Dir = filepath.Join(repoRoot, d)\n        if out, err := cmd.CombinedOutput(); err != nil {\n            return fmt.Errorf(\"preflight go build in %s: %w\\n%s\", d, err, out)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := runApidiff(repoRoot, dirs, afterDir); err != nil {\n    return fmt.Errorf(\"run apidiff on working tree (check per-module stderr; ensure modules build): %w\", err)\n}","preventionTips":["Ensure the working tree compiles before running the tool (`go build ./...`).","Keep go.mod and vendor in sync in the modules being diffed.","Pin apidiff to a version compatible with the repo's Go toolchain."],"tags":["apidiff","tooling","go","kubernetes","build","modules"],"analyzedSha":"b882c60b4023bdf09264c2d5d30a2cadebc240fb","analyzedAt":"2026-08-07T04:07:48.144Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}