{"record":{"id":"3ae7571ee4086cbc","repo":"slimtoolkit/slim","slug":"failed-to-scan-files-w","errorCode":null,"errorMessage":"failed to scan files: %w","messagePattern":"failed to scan files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/imagebuilder/internalbuilder/engine.go","lineNumber":324,"sourceCode":"\n\t\tif err := tw.WriteHeader(hdr); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write tar header: %w\", err)\n\t\t}\n\t\tif !info.IsDir() {\n\t\t\tf, err := os.Open(fp)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif _, err := io.Copy(tw, f); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to read file into the tar: %w\", err)\n\t\t\t}\n\t\t\tf.Close()\n\t\t}\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to scan files: %w\", err)\n\t}\n\tif err := tw.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to finish tar: %w\", err)\n\t}\n\n\treturn tarball.LayerFromReader(&b)\n}\n","sourceCodeStart":306,"sourceCodeEnd":332,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/imagebuilder/internalbuilder/engine.go#L306-L332","documentation":"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).","triggerScenarios":"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.","commonSituations":"Layer directory containing symlinks/devices (via 203), permission-denied on the layer root, or the directory vanishing mid-build.","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."],"exampleFix":"// before\nos.Chmod(\"/build/rootfs\", 0o000) // walk cannot read root\n// after\nos.Chmod(\"/build/rootfs\", 0o755)\nlayerFromDir(LayerDataInfo{Source: \"/build/rootfs\"})","handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(src); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"cannot scan layer dir %q: %v\", src, err)\n}\nif !isReadable(src) { return fmt.Errorf(\"layer dir not readable: %s\", src) }","typeGuard":null,"tryCatchPattern":"layer, err := build(ctx, opts)\nvar pathErr *fs.PathError\nif errors.As(err, &pathErr) || strings.Contains(err.Error(), \"failed to scan files\") {\n    // log errors.Unwrap chain, fix perms/unsupported types, retry\n}","preventionTips":["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"],"tags":["filesystem","tar","walk","image-build"],"backgroundTag":"directory-walk-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}