{"record":{"id":"3968b9bac140dc38","repo":"vitessio/vitess","slug":"goimport-error-w","errorCode":null,"errorMessage":"goimport error: %w","messagePattern":"goimport error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/asthelpergen/asthelpergen.go","lineNumber":234,"sourceCode":"\t\tresult[fullPath] = genFile\n\t}\n\n\treturn result, nil\n}\n\n// VerifyFilesOnDisk compares the generated results from the codegen against the files that\n// currently exist on disk and returns any mismatches\nfunc VerifyFilesOnDisk(result map[string]*jen.File) (errors []error) {\n\tfor fullPath, file := range result {\n\t\texisting, err := os.ReadFile(fullPath)\n\t\tif err != nil {\n\t\t\terrors = append(errors, fmt.Errorf(\"missing file on disk: %s (%w)\", fullPath, err))\n\t\t\tcontinue\n\t\t}\n\n\t\tgenFile, err := codegen.FormatJenFile(file)\n\t\tif err != nil {\n\t\t\terrors = append(errors, fmt.Errorf(\"goimport error: %w\", err))\n\t\t\tcontinue\n\t\t}\n\n\t\tif !bytes.Equal(existing, genFile) {\n\t\t\terrors = append(errors, fmt.Errorf(\"'%s' has changed\", fullPath))\n\t\t\tcontinue\n\t\t}\n\t}\n\treturn errors\n}\n\n// Options configures the AST helper generation process.\ntype Options struct {\n\t// Packages specifies the Go packages to analyze for AST types.\n\t// Can be package paths like \"./mypackage\" or import paths like \"github.com/example/ast\".\n\tPackages []string\n\n\t// RootInterface is the fully qualified name of the root interface that all AST nodes implement.","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/asthelpergen/asthelpergen.go#L216-L252","documentation":"After reading the existing file, VerifyFilesOnDisk runs codegen.FormatJenFile (goimports) over the generated source. If formatting fails, this error is collected with the underlying goimports error wrapped.","triggerScenarios":"code generation produced source that goimports cannot parse or resolve, typically due to a bug in a generator template or a missing/unresolvable import in the generated file.","commonSituations":"A new generator emits invalid Go syntax; imports for new packages are missing from the environment; a generator change breaks the emitted file structure.","solutions":["Fix the generator code producing the malformed output (check the wrapped error for the parse position)","Run `go mod tidy` so goimports can resolve all imports in the generated package","Regenerate with `asthelpergen` after fixing to confirm formatting succeeds"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"errors := VerifyFilesOnDisk(result)\nfor _, err := range errors {\n    if strings.Contains(err.Error(), \"goimport error\") {\n        log.Printf(\"generator produced unformattable output: %v\", err)\n    }\n}","preventionTips":["Ensure all imports referenced by generated code exist in go.mod","Run `go mod tidy` before codegen verification","Test generators on small inputs to catch syntax bugs early"],"tags":["codegen","goimports","formatting"],"backgroundTag":"goimports-format-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}