urfave/cli · error
goimports needed
Error message
goimports needed
What it means
LintActionFunc runs goimports -l over the codebase and fails the build with this error if the output is non-empty, meaning at least one file is not formatted according to goimports. It is an intentional lint gate, not a runtime fault: some source files need import fixes or formatting.
Source
Thrown at scripts/build.go:647
)
}
func LintActionFunc(ctx context.Context, cmd *cli.Command) error {
topDir := cmd.String("top-dir")
if err := os.Chdir(topDir); err != nil {
return err
}
out, err := sh(ctx, filepath.Join(topDir, ".local/bin/goimports"), "-l", ".")
if err != nil {
return err
}
if strings.TrimSpace(out) != "" {
fmt.Fprintln(cmd.ErrWriter, "# ---> goimports -l is non-empty:")
fmt.Fprintln(cmd.ErrWriter, out)
return errors.New("goimports needed")
}
return nil
}
func V3Diff(ctx context.Context, cmd *cli.Command) error {
if err := os.Chdir(cmd.String("top-dir")); err != nil {
return err
}
err := runCmd(
ctx,
"diff",
"--ignore-all-space",
"--minimal",
"--color="+func() string {
if cmd.Bool("color") {
return "always"View on GitHub (pinned to 1a4deb4f5a)
Solutions
- Run goimports -w . (or gofmt -s -w .) on the repo to auto-fix all listed files, then re-run lint.
- Configure your editor to run goimports on save so files are formatted before commit.
- If CI disagrees with local results, align the Go/goimports toolchain version with CI.
Example fix
// before (CI step) ./build lint # fails: goimports needed // after add a pre-commit/CI step: goimports -l -w . && ./build lint
Defensive patterns
Strategy: fallback
Validate before calling
out, err := exec.Command("goimports", "-l", ".").Output()
if err == nil && len(out) == 0 {
// safe to proceed
} Try / catch
if err := lint(ctx, cmd); err != nil {
if strings.Contains(err.Error(), "goimports needed") {
if fix := exec.Command("goimports", "-w", "."); fix.Run() == nil {
return lint(ctx, cmd) // retry after auto-format
}
}
return err
} Prevention
- Run goimports -w on save in your editor.
- Add a pre-commit hook running goimports -l and blocking non-formatted files.
- Keep your local Go/goimports versions aligned with CI.
When it happens
Trigger: Committing code with unsorted/mis-formatted imports or gofmt divergence, then running the lint action (e.g. ./build lint). Any file listed by goimports -l triggers it.
Common situations: Editing files without running goimports, merge conflicts resolved with stray formatting, adding imports manually in the wrong group, or a different local goimports version than CI.
Related errors
- empty github token
- parse error
- got nil/empty layouts slice
- invalid value %q for argument %s: %v
- args %s has max 0, not parsing argument
AI-assisted analysis of urfave/cli@1a4deb4f5a (2026-08-31).
Data as JSON: /api/errors/cc39af34a7470aa7.
Report an issue: GitHub.