slimtoolkit/slim · error
failed to scan files: %w
Error message
failed to scan files: %w
What it means
filepath.Walk over the layer directory returned an error, which is wrapped as "failed to scan files". Note the walk callback swallows per-file errors (returns nil), so this error comes from the walk machinery itself — e.g. the root directory is unreadable — or from any of the wrapped callback errors (relative path, tar header, unsupported type, copy).
Source
Thrown at pkg/imagebuilder/internalbuilder/engine.go:324
if err := tw.WriteHeader(hdr); err != nil {
return fmt.Errorf("failed to write tar header: %w", err)
}
if !info.IsDir() {
f, err := os.Open(fp)
if err != nil {
return err
}
if _, err := io.Copy(tw, f); err != nil {
return fmt.Errorf("failed to read file into the tar: %w", err)
}
f.Close()
}
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to scan files: %w", err)
}
if err := tw.Close(); err != nil {
return nil, fmt.Errorf("failed to finish tar: %w", err)
}
return tarball.LayerFromReader(&b)
}
View on GitHub (pinned to 81940d17fa)
Solutions
- Unwrap the error to find the root cause (unsupported file type vs. traversal failure).
- Remove unsupported file types from the layer directory.
- Verify read permissions on the layer directory and its contents.
Example fix
// before
os.Chmod("/build/rootfs", 0o000) // walk cannot read root
// after
os.Chmod("/build/rootfs", 0o755)
layerFromDir(LayerDataInfo{Source: "/build/rootfs"}) Defensive patterns
Strategy: try-catch
Validate before calling
if info, err := os.Stat(src); err != nil || !info.IsDir() {
return fmt.Errorf("cannot scan layer dir %q: %v", src, err)
}
if !isReadable(src) { return fmt.Errorf("layer dir not readable: %s", src) } Try / catch
layer, err := build(ctx, opts)
var pathErr *fs.PathError
if errors.As(err, &pathErr) || strings.Contains(err.Error(), "failed to scan files") {
// log errors.Unwrap chain, fix perms/unsupported types, retry
} Prevention
- Always unwrap this error to find the real cause (it aggregates several failures)
- Pre-check readability of the whole layer tree
- Eliminate concurrent modification of the layer directory
When it happens
Trigger: Any error escaping the walk callback (unsupported file type 203, header 204, copy 205, relative path 202) or filepath.Walk failing to traverse the root of input.Source.
Common situations: Layer directory containing symlinks/devices (via 203), permission-denied on the layer root, or the directory vanishing mid-build.
Related errors
- failed to calculate relative path: %w
- not implemented archiving file type %s (%s)
- failed to read file into the tar: %w
- bad output tar - %s
- failed to write tar header: %w
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/3ae7571ee4086cbc.
Report an issue: GitHub.