golang/go · error
zip: cannot add non-regular file
Error message
zip: cannot add non-regular file
What it means
Error "zip: cannot add non-regular file" thrown in golang/go.
Source
Thrown at src/archive/zip/writer.go:576
}
// AddFS adds the files from fs.FS to the archive.
// It walks the directory tree starting at the root of the filesystem
// adding each file to the zip using deflate while maintaining the directory structure.
func (w *Writer) AddFS(fsys fs.FS) error {
return fs.WalkDir(fsys, ".", func(name string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if name == "." {
return nil
}
info, err := d.Info()
if err != nil {
return err
}
if !d.IsDir() && !info.Mode().IsRegular() {
return errors.New("zip: cannot add non-regular file")
}
h, err := FileInfoHeader(info)
if err != nil {
return err
}
h.Name = name
if d.IsDir() {
h.Name += "/"
}
h.Method = Deflate
fw, err := w.CreateHeader(h)
if err != nil {
return err
}
if d.IsDir() {
return nil
}
f, err := fsys.Open(name)View on GitHub (pinned to b6b368adc5)
When it happens
Trigger: Thrown at src/archive/zip/writer.go:576 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/79f7edd075f6a92e.
Report an issue: GitHub.