apache/beam · error
error writing debug data to file after err
Error message
error writing debug data to file after err %v:%v
What it means
In starcgen.Generate, after e.FromAsts reports an extraction error, the generator tries to write the accumulated debug output (e.Bytes()) to the output writer so developers can diagnose the failure. If THAT debug write itself fails, this error is returned, combining the original extraction error and the write error. It masks the primary failure path, so both values matter.
Solutions
- Fix the write target first: ensure the output file/pipe is writable and not closed or full.
- Then fix the original 'error extracting from asts' reported inside the message.
- Check disk space and permissions on the output path before running starcgen.
- Capture full stdout/stderr instead of piping into commands that close early.
Example fix
// before
f, _ := os.Create(outPath)
f.Close()
gen.Generate(f, ...) // writes to closed file
// after
f, err := os.Create(outPath)
if err != nil { return err }
defer f.Close()
gen.Generate(f, ...) Defensive patterns
Strategy: validation
Validate before calling
if f, ok := w.(*os.File); ok {
if _, err := f.Stat(); err != nil { return fmt.Errorf("output file unusable: %w", err) }
} Try / catch
err := gen.Generate(w, ...)
if err != nil && strings.Contains(err.Error(), "error writing debug data") {
log.Printf("both extraction and debug write failed: %v", err)
} Prevention
- Always check errors from os.Create and defer Close until after Generate finishes.
- Verify free disk space before large code-generation runs.
- Avoid piping generator output into commands that close early (e.g. head).
When it happens
Trigger: FromAsts fails (e.g. a Go source file in --inputs cannot be imported/parsed) AND the io.Writer passed to Generate returns an error when the debug bytes are written (e.g. closed writer, disk full, invalid file).
Common situations: Redirecting starcgen output to a full disk or read-only file; piping to a closed pipe (e.g. `starcgen | head`); passing an already-closed os.File as the output writer.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- short write of data got
- broken invariant: idsFound map is nil, but idsRequired map…
- bucket must not be empty
- chunk write failed
- couldn't find the following identifiers; please check for…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/46755c565463aa63.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/cmd/starcgen/starcgen.go:81
intendedPkg = flag.String("package", "", "a filter on input go files. Required if inputs unset.")
output = flag.String("output", "", "output file with types to create")
ids = flag.String("identifiers", "", "comma separated list of package local identifiers for which to generate code")
debug = flag.Bool("debug", false, "print out a debugging header in the shim file to help diagnose errors")
)
// Generate takes the typechecked inputs, and generates the shim file for the relevant
// identifiers.
func Generate(w io.Writer, filename, pkg string, ids []string, fset *token.FileSet, files []*ast.File) error {
e := starcgenx.NewExtractor(pkg)
e.Ids = ids
e.Debug = *debug
// Importing from source should work in most cases.
imp := importer.For("source", nil)
if err := e.FromAsts(imp, fset, files); err != nil {
// Always print out the debugging info to the file.
if _, errw := w.Write(e.Bytes()); errw != nil {
return fmt.Errorf("error writing debug data to file after err %v:%v", err, errw)
}
err = fmt.Errorf("error extracting from asts: %v", err)
e.Printf("%v", err)
return err
}
data := e.Generate(filename)
if err := write(w, []byte(license)); err != nil {
return err
}
return write(w, data)
}
func write(w io.Writer, data []byte) error {
n, err := w.Write(data)
if err != nil && n < len(data) {
return fmt.Errorf("short write of data got %d, want %d", n, len(data))
}
return errView on GitHub (pinned to 12126d8942)