wavetermdev/waveterm · error
gofmt failed: %w Output: %s
Error message
gofmt failed: %w Output: %s
What it means
FormatGoFile runs `gofmt -w <filePath>` and captures combined stdout/stderr. If gofmt exits non-zero — meaning the Go source has syntax errors or gofmt could not write the file — the error is wrapped as "gofmt failed" including the process output. The output section contains gofmt's own diagnostic, typically the parse error with line/column.
Source
Thrown at pkg/waveappstore/waveappstore.go:435
}
filePath, err := validateAndResolveFilePath(appDir, fileName)
if err != nil {
return err
}
if filepath.Ext(filePath) != ".go" {
return fmt.Errorf("file is not a Go file: %s", fileName)
}
gofmtPath, err := waveapputil.ResolveGoFmtPath()
if err != nil {
return fmt.Errorf("failed to resolve gofmt path: %w", err)
}
cmd := exec.Command(gofmtPath, "-w", filePath)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("gofmt failed: %w\nOutput: %s", err, string(output))
}
return nil
}
func ListAllAppFiles(appId string) (*fileutil.ReadDirResult, error) {
if err := ValidateAppId(appId); err != nil {
return nil, fmt.Errorf("invalid appId: %w", err)
}
appDir, err := GetAppDir(appId)
if err != nil {
return nil, err
}
if _, err := os.Stat(appDir); os.IsNotExist(err) {
return nil, fmt.Errorf("app directory does not exist: %s", appDir)
}View on GitHub (pinned to a4447c1563)
Solutions
- Read the `Output:` portion of the error — gofmt reports the exact line/column of the syntax error — and fix the source
- Only invoke format on parseable files; run a parser/linter check first if available
- Check file write permissions if the syntax looks valid (gofmt -w needs write access)
- Fix the syntax error at the reported location and retry FormatGoFile
Example fix
// before
func main() {
fmt.Println("hi")
// after
func main() {
fmt.Println("hi")
} Defensive patterns
Strategy: try-catch
Validate before calling
if err := parser.ParseFile(token.NewFileSet(), filePath, nil, parser.ParseComments); err != nil {
return fmt.Errorf("file has syntax errors, fix before formatting: %v", err)
} Try / catch
if err := FormatGoFile(appId, fileName); err != nil {
if strings.Contains(err.Error(), "gofmt failed") {
var gofmtOutput string
if idx := strings.Index(err.Error(), "Output: "); idx >= 0 {
gofmtOutput = err.Error()[idx+len("Output: "):]
}
return fmt.Errorf("syntax error in %s: %s", fileName, gofmtOutput)
}
return err
} Prevention
- Fix gofmt-reported line/column errors before retrying formatting
- Avoid formatting files mid-edit or with unfilled template placeholders
- Keep files writable by the server user so gofmt -w can save in place
When it happens
Trigger: Running FormatGoFile on a .go file containing syntax errors (unclosed brace, invalid tokens) or a file gofmt cannot write (permissions/locked file).
Common situations: Saving a partially edited Go file and hitting format before it parses; generated code with template placeholders not yet filled in; corrupted file from an interrupted write.
Related errors
- json syntax error at line %d, col %d: probably an extra trai
- json syntax error at line %d, col %d: %v
- beginning of file
- procinfo: process not found
- integer overflow
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/13080f20cc7451f2.
Report an issue: GitHub.