{"record":{"id":"57b686b8f968c940","repo":"slimtoolkit/slim","slug":"no-file-s","errorCode":null,"errorMessage":"no file - %s","messagePattern":"no file - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerimage/dockerimage.go","lineNumber":2171,"sourceCode":"\t\t}\n\n\t\tif hdr == nil || hdr.Name == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\thdr.Name = filepath.Clean(hdr.Name)\n\t\tif hdr.Name == filePath {\n\t\t\tswitch hdr.Typeflag {\n\t\t\tcase tar.TypeReg, tar.TypeSymlink, tar.TypeLink:\n\t\t\t\treturn TarReadCloser{\n\t\t\t\t\tReader: tr,\n\t\t\t\t\tCloser: tfile,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil, fmt.Errorf(\"no file - %s\", filePath)\n}\n\nfunc FileDataFromTar(tarPath, filePath string) ([]byte, error) {\n\ttfile, err := os.Open(tarPath)\n\tif err != nil {\n\t\tlog.Errorf(\"dockerimage.FileDataFromTar: os.Open error - %v\", err)\n\t\treturn nil, err\n\t}\n\n\tdefer tfile.Close()\n\ttr := tar.NewReader(tfile)\n\n\tfor {\n\t\thdr, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n","sourceCodeStart":2153,"sourceCodeEnd":2189,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerimage/dockerimage.go#L2153-L2189","documentation":"FileDataFromTar extracts a single file from a tar archive; when it finishes scanning all entries without finding one whose name matches filePath, it returns fmt.Errorf(\"no file - %s\", filePath). It means the requested path simply does not exist in the tar archive at that exact name, not an archive corruption or read failure.","triggerScenarios":"Calling FileDataFromTar(tarPath, filePath) where no tar header entry equals filePath exactly (name mismatch, leading ./, directory-only archive, or the file was never added to the tar).","commonSituations":"Building image layers where a metadata file (e.g. manifest.json, config blob) is expected in a layer tar but the Dockerfile build omitted it; path normalization differences (./app/file vs app/file); extracting from a Docker image export tar where the path lives in a different layer.","solutions":["Print the tar's entry names (iterate tar.Next and log tr.Name) and compare against the filePath you pass; fix the path to the exact stored name","Strip/normalize the requested path (trim leading './' or '/') to match how entries were stored","Verify the build step that creates the tar actually writes the file before FileDataFromTar is called","Check you are reading the correct tar archive (right layer/image ID) — the file may exist in another tar"],"exampleFix":"// before\nname := \"./manifest.json\"\ndata, err := FileDataFromTar(tarPath, name) // \"no file - ./manifest.json\"\n// after\nname := strings.TrimPrefix(name, \"./\")\ndata, err := FileDataFromTar(tarPath, name)","handlingStrategy":"validation","validationCode":"func tarContainsFile(tarPath, filePath string) bool {\n    f, err := os.Open(tarPath)\n    if err != nil { return false }\n    defer f.Close()\n    want := strings.TrimPrefix(strings.TrimPrefix(filePath, \"/\"), \"./\")\n    tr := tar.NewReader(f)\n    for {\n        hdr, err := tr.Next()\n        if err != nil { return false }\n        if strings.TrimPrefix(strings.TrimPrefix(hdr.Name, \"/\"), \"./\") == want { return true }\n    }\n}","typeGuard":"if !tarContainsFile(tarPath, filePath) { return nil, fmt.Errorf(\"entry %q not present in %s\", filePath, tarPath) }","tryCatchPattern":"data, err := FileDataFromTar(tarPath, filePath)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"no file - \") {\n        log.Warnf(\"entry %s missing from tar; listing entries for diagnosis\", filePath)\n        // fall back to scanning alternate layers or skip\n        return nil, ErrEntryNotInTar\n    }\n    return err\n}","preventionTips":["Log all tar entry names when an extraction fails, to compare with the requested path","Normalize paths (strip leading ./ and /) both when writing and reading tar entries","Add a unit test asserting the file you expect is written into the tar before extraction","Verify the tar file exists and is non-empty before scanning"],"tags":["tar","file-not-found","docker-image"],"backgroundTag":"file-not-found-in-archive","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}