vitessio/vitess · error

goimport error: %w

Error message

goimport error: %w

What it means

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.

Source

Thrown at go/tools/asthelpergen/asthelpergen.go:234

		result[fullPath] = genFile
	}

	return result, nil
}

// VerifyFilesOnDisk compares the generated results from the codegen against the files that
// currently exist on disk and returns any mismatches
func VerifyFilesOnDisk(result map[string]*jen.File) (errors []error) {
	for fullPath, file := range result {
		existing, err := os.ReadFile(fullPath)
		if err != nil {
			errors = append(errors, fmt.Errorf("missing file on disk: %s (%w)", fullPath, err))
			continue
		}

		genFile, err := codegen.FormatJenFile(file)
		if err != nil {
			errors = append(errors, fmt.Errorf("goimport error: %w", err))
			continue
		}

		if !bytes.Equal(existing, genFile) {
			errors = append(errors, fmt.Errorf("'%s' has changed", fullPath))
			continue
		}
	}
	return errors
}

// Options configures the AST helper generation process.
type Options struct {
	// Packages specifies the Go packages to analyze for AST types.
	// Can be package paths like "./mypackage" or import paths like "github.com/example/ast".
	Packages []string

	// RootInterface is the fully qualified name of the root interface that all AST nodes implement.

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Fix the generator code producing the malformed output (check the wrapped error for the parse position)
  2. Run `go mod tidy` so goimports can resolve all imports in the generated package
  3. Regenerate with `asthelpergen` after fixing to confirm formatting succeeds
Defensive patterns

Strategy: try-catch

Try / catch

errors := VerifyFilesOnDisk(result)
for _, err := range errors {
    if strings.Contains(err.Error(), "goimport error") {
        log.Printf("generator produced unformattable output: %v", err)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: A new generator emits invalid Go syntax; imports for new packages are missing from the environment; a generator change breaks the emitted file structure.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/3968b9bac140dc38. Report an issue: GitHub.