slimtoolkit/slim · error
bad file - %s
Error message
bad file - %s
What it means
ArchiveFiles rejects any input file entry that fails its sanity check (non-regular file, e.g. a directory, symlink, socket, or a file whose stat fails in a way that disqualifies it). It logs "fsutil.ArchiveFiles: bad file" and returns immediately, so the entire archive is abandoned rather than skipped.
Source
Thrown at pkg/util/fsutil/fsutil.go:1425
}
th.Name = fpRewrite(fname, true, addPrefix)
if err := tw.WriteHeader(th); err != nil {
return err
}
f, err := os.Open(fname)
if err != nil {
return err
}
defer close(f)
if _, err := io.CopyN(tw, f, th.Size); err != nil {
return fmt.Errorf("cannot write %s file: %w", fname, err)
}
} else {
log.Errorf("fsutil.ArchiveFiles: bad file - %s", fname)
return fmt.Errorf("bad file - %s", fname)
}
}
return nil
}
func ArchiveDir(afname string,
d2aname string,
trimPrefix string,
addPrefix string) error {
dirInfo, err := os.Stat(d2aname)
if err != nil {
return err
}
if !dirInfo.IsDir() {
return fmt.Errorf("not a directory")
}View on GitHub (pinned to 81940d17fa)
Solutions
- Verify each input path is a regular file (os.Stat + Mode().IsRegular()) before calling ArchiveFiles.
- Resolve symlinks to real files or remove dangling ones from the input list.
- Filter directories out of glob results before passing the list to ArchiveFiles.
Example fix
// before
fsutil.ArchiveFiles(tw, []string{"/data", "/data/a.txt"})
// after
info, _ := os.Stat("/data/a.txt")
if info.Mode().IsRegular() {
fsutil.ArchiveFiles(tw, []string{"/data/a.txt"})
} Defensive patterns
Strategy: validation
Validate before calling
func onlyRegularFiles(paths []string) ([]string, error) {
var out []string
for _, p := range paths {
fi, err := os.Stat(p)
if err != nil { return nil, err }
if fi.Mode().IsRegular() { out = append(out, p) }
}
return out, nil
} Try / catch
if err := fsutil.ArchiveFiles(tw, files); err != nil {
if strings.HasPrefix(err.Error(), "bad file - ") {
log.Warnf("skipping invalid input: %v", err)
}
return err
} Prevention
- Filter glob results to regular files only before archiving.
- Resolve and verify symlinks point to existing regular files.
- Keep explicit file lists instead of passing directories.
When it happens
Trigger: Passing a path that is not a regular file to fsutil.ArchiveFiles (via Archive or OnCommand) — most commonly a directory path, a dangling symlink, or a special device file.
Common situations: Globbing patterns that expand to directories, config that lists a directory instead of files, or symlinks left pointing at removed targets.
Related errors
- cannot write %s file: %w
- not a directory
- invalid context directory
- invalid Dockerfile
- bad output tar - %s
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/77735c6638abf54d.
Report an issue: GitHub.