slimtoolkit/slim · error
not a directory
Error message
not a directory
What it means
ArchiveDir first os.Stat's the directory to archive; if the stat succeeds but the path is not a directory, it returns this sentinel error. It guards against archiving a regular file or symlink passed as the directory argument (a pre-existing os.Create(afname) would then clobber output).
Source
Thrown at pkg/util/fsutil/fsutil.go:1442
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")
}
tf, err := os.Create(afname)
if err != nil {
return err
}
defer close(tf)
tw := tar.NewWriter(tf)
defer close(tw)
onFSObject := func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Errorf("fsutil.ArchiveDir.onFSObject: path=%q err=%q", path, err)
return err
}
View on GitHub (pinned to 81940d17fa)
Solutions
- Verify the path with os.Stat and info.IsDir() before calling ArchiveDir.
- If you meant to archive a single file, use ArchiveFiles/Archive instead of ArchiveDir.
- Fix the path configuration to point to the actual artifact directory.
Example fix
// before
fsutil.ArchiveDir("/out/artifacts.tar", "/cfg/artifacts.yaml")
// after
if fi, err := os.Stat("/cfg/artifacts"); err == nil && fi.IsDir() {
fsutil.ArchiveDir("/out/artifacts.tar", "/cfg/artifacts")
} Defensive patterns
Strategy: validation
Validate before calling
fi, err := os.Stat(dirPath)
if err != nil {
return fmt.Errorf("cannot access %s: %w", dirPath, err)
}
if !fi.IsDir() {
return fmt.Errorf("%s is not a directory", dirPath)
} Try / catch
if err := fsutil.ArchiveDir(afname, dname); err != nil {
if err.Error() == "not a directory" {
return fmt.Errorf("configured artifact path %s is a file; fix config", dname)
}
return err
} Prevention
- Validate the directory path at config-load time, not at archive time.
- Use explicit config keys distinguishing file vs directory artifact paths.
- Check for symlinks that were turned into files by deployments.
When it happens
Trigger: Calling fsutil.ArchiveDir (via archiveArtifacts) with a d2aname path that exists but is a regular file or symlink rather than a directory.
Common situations: Config pointing at an artifact file instead of the directory containing it, a directory replaced by a symlink after a deploy, or a path typo resolving to a file.
Related errors
- cannot write %s file: %w
- bad file - %s
- invalid context directory
- podPort cannot be empty
- file path is not absolute
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/3a1d77ba44ec4447.
Report an issue: GitHub.