golang/go · error
zip: writer closed twice
Error message
zip: writer closed twice
What it means
Error "zip: writer closed twice" thrown in golang/go.
Source
Thrown at src/archive/zip/writer.go:90
func (w *Writer) SetComment(comment string) error {
if len(comment) > uint16max {
return errors.New("zip: Writer.Comment too long")
}
w.comment = comment
return nil
}
// Close finishes writing the zip file by writing the central directory.
// It does not close the underlying writer.
func (w *Writer) Close() error {
if w.last != nil && !w.last.closed {
if err := w.last.close(); err != nil {
return err
}
w.last = nil
}
if w.closed {
return errors.New("zip: writer closed twice")
}
w.closed = true
// write central directory
start := w.cw.count
usedZip64 := false
for _, h := range w.dir {
// For the Central Directory, we always have the correct sizes.
//
// Implementations disagree on what triggers the inclusion of a Zip64
// extra field: Info-ZIP only writes it if any size or offset EXCEEDS
// 4GiB - 1, while libarchive writes it if any size REACHES OR EXCEEDS
// 4GiB - 1, or if the offset EXCEEDS 4GiB - 1. The spec is ambiguous.
//
// We conservatively write Zip64 extra fields if any size or offset
// REACHES OR EXCEEDS 4GiB - 1, to maximize compatibility with readers.
// There is no ambiguity in parsing, so there is no downside to it.
//View on GitHub (pinned to b6b368adc5)
When it happens
Trigger: Thrown at src/archive/zip/writer.go:90 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/6fcde76b9eeee631.
Report an issue: GitHub.