{"record":{"id":"856da1e5edff7ef6","repo":"apache/beam","slug":"short-write-of-data-got-d-want-d","errorCode":null,"errorMessage":"short write of data got %d, want %d","messagePattern":"short write of data got (.+?), want (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/cmd/starcgen/starcgen.go","lineNumber":97,"sourceCode":"\t\t// Always print out the debugging info to the file.\n\t\tif _, errw := w.Write(e.Bytes()); errw != nil {\n\t\t\treturn fmt.Errorf(\"error writing debug data to file after err %v:%v\", err, errw)\n\t\t}\n\t\terr = fmt.Errorf(\"error extracting from asts: %v\", err)\n\t\te.Printf(\"%v\", err)\n\t\treturn err\n\t}\n\tdata := e.Generate(filename)\n\tif err := write(w, []byte(license)); err != nil {\n\t\treturn err\n\t}\n\treturn write(w, data)\n}\n\nfunc write(w io.Writer, data []byte) error {\n\tn, err := w.Write(data)\n\tif err != nil && n < len(data) {\n\t\treturn fmt.Errorf(\"short write of data got %d, want %d\", n, len(data))\n\t}\n\treturn err\n}\n\nfunc usage() {\n\tfmt.Fprintf(os.Stderr, \"Usage: %v [options] --inputs=<comma separated of go files>\\n\", filepath.Base(os.Args[0]))\n\tflag.PrintDefaults()\n}\n\nfunc main() {\n\tflag.Usage = usage\n\tflag.Parse()\n\n\tlog.SetFlags(log.Lshortfile)\n\tlog.SetPrefix(\"starcgen: \")\n\n\tdir, err := filepath.Abs(filepath.Dir(os.Args[0]))\n\tif err != nil {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/cmd/starcgen/starcgen.go#L79-L115","documentation":"The starcgen write helper detects a partial write: io.Writer returned n < len(data). It signals that the generated output (license header or generated code) was not fully written. Note the condition also requires err != nil, so this usually accompanies an underlying write error which is returned as well.","triggerScenarios":"Calling Generate (which calls write) with an io.Writer that accepts fewer bytes than requested and returns an error, e.g. a limited buffer, a failing network/file writer, or a custom writer with a short-write bug.","commonSituations":"Writing generated code to a custom in-memory writer with a fixed-size buffer; disk-full conditions; faulty wrappers around os.File that mishandle n.","solutions":["Inspect the error returned alongside it (write returns the underlying err too).","Replace short/custom writers with os.File or bytes.Buffer for starcgen output.","Free disk space or fix the underlying storage error.","If using a custom writer, fix it to return io.ErrShortWrite semantics correctly or loop writes until all bytes are consumed."],"exampleFix":"// before\nw := bytes.NewBuffer(make([]byte, 0, 16)) // too small, custom truncating writer\ngen.Generate(w, ...)\n// after\nw := &bytes.Buffer{} // unbounded, correct io.Writer semantics\ngen.Generate(w, ...)","handlingStrategy":"validation","validationCode":"var probe [1]byte\nif _, err := w.Write(probe[:]); err != nil { return fmt.Errorf(\"writer not ready: %w\", err) }","typeGuard":null,"tryCatchPattern":"err := gen.Generate(w, ...)\nif err != nil && strings.Contains(err.Error(), \"short write\") {\n\tlog.Printf(\"underlying write error: %v\", err)\n}","preventionTips":["Use standard writers (bytes.Buffer, os.File) with correct io.Writer semantics.","Fix custom writers to loop until all bytes are written or return io.ErrShortWrite.","Monitor disk space on generation output paths."],"tags":["go","io","code-generation","short-write"],"backgroundTag":"file-write-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}