golang/go · error
copying %s to %s: %v
Error message
copying %s to %s: %v
What it means
A wrapper that fires when copying an object file (ofile) into an archive (afile) fails for any reason - including the file-larger-than-stat case (1193), an unexpected EOF where the file shrank (n < size), or a raw I/O error from io.Copy. The placeholders are the source object path and the destination archive path.
Source
Thrown at src/cmd/go/internal/work/gc.go:528
// about bytes, not runes.
name := fi.Name()
if len(name) > 16 {
name = name[:16]
} else {
name += strings.Repeat(" ", 16-len(name))
}
size := fi.Size()
fmt.Fprintf(w, "%s%-12d%-6d%-6d%-8o%-10d`\n",
name, 0, 0, 0, 0644, size)
n, err := io.Copy(w, src)
src.Close()
if err == nil && n < size {
err = io.ErrUnexpectedEOF
} else if err == nil && n > size {
err = fmt.Errorf("file larger than size reported by stat")
}
if err != nil {
return fmt.Errorf("copying %s to %s: %v", ofile, afile, err)
}
if size&1 != 0 {
w.WriteByte(0)
}
}
if err := w.Flush(); err != nil {
return err
}
return dst.Close()
}
// setextld sets the appropriate linker flags for the specified compiler.
func setextld(ldflags []string, compiler []string) ([]string, error) {
for _, f := range ldflags {
if f == "-extld" || strings.HasPrefix(f, "-extld=") {
// don't override -extld if supplied
return ldflags, nilView on GitHub (pinned to b6b368adc5)
Solutions
- Run `go clean -cache` and rebuild
- Ensure no concurrent builds modify the same object files
- Check disk space and filesystem health
Example fix
// before go build ./... // after go clean -cache && go build ./...
Defensive patterns
Strategy: retry
Try / catch
// Archive copy failed (race or I/O): clean and retry
if bytes.Contains(out, []byte("copying")) && bytes.Contains(out, []byte("to")) {
exec.Command("go", "clean", "-cache").Run()
out, err = cmd.CombinedOutput()
} Prevention
- Run a single build at a time per work directory
- Keep GOCACHE and the build output on reliable local storage
- Monitor disk space during large builds
When it happens
Trigger: Fires in the archive builder after io.Copy when err != nil (short read, long read, or copy failure), wrapping the underlying error with source and destination paths.
Common situations: Concurrent modification of object files, a full disk, broken build artifacts, or filesystem errors during the archive step.
Related errors
- file larger than size reported by stat
- copying %s to %s: %v
- corrupt archive
- truncated archive
- archive/tar: sockets not supported
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/38f12a39b62f0684.
Report an issue: GitHub.