slimtoolkit/slim · error

no file - %s

Error message

no file - %s

What it means

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.

Source

Thrown at pkg/docker/dockerimage/dockerimage.go:2171

		}

		if hdr == nil || hdr.Name == "" {
			continue
		}

		hdr.Name = filepath.Clean(hdr.Name)
		if hdr.Name == filePath {
			switch hdr.Typeflag {
			case tar.TypeReg, tar.TypeSymlink, tar.TypeLink:
				return TarReadCloser{
					Reader: tr,
					Closer: tfile,
				}, nil
			}
		}
	}

	return nil, fmt.Errorf("no file - %s", filePath)
}

func FileDataFromTar(tarPath, filePath string) ([]byte, error) {
	tfile, err := os.Open(tarPath)
	if err != nil {
		log.Errorf("dockerimage.FileDataFromTar: os.Open error - %v", err)
		return nil, err
	}

	defer tfile.Close()
	tr := tar.NewReader(tfile)

	for {
		hdr, err := tr.Next()
		if err == io.EOF {
			break
		}

View on GitHub (pinned to 81940d17fa)

Solutions

  1. 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
  2. Strip/normalize the requested path (trim leading './' or '/') to match how entries were stored
  3. Verify the build step that creates the tar actually writes the file before FileDataFromTar is called
  4. Check you are reading the correct tar archive (right layer/image ID) — the file may exist in another tar

Example fix

// before
name := "./manifest.json"
data, err := FileDataFromTar(tarPath, name) // "no file - ./manifest.json"
// after
name := strings.TrimPrefix(name, "./")
data, err := FileDataFromTar(tarPath, name)
Defensive patterns

Strategy: validation

Validate before calling

func tarContainsFile(tarPath, filePath string) bool {
    f, err := os.Open(tarPath)
    if err != nil { return false }
    defer f.Close()
    want := strings.TrimPrefix(strings.TrimPrefix(filePath, "/"), "./")
    tr := tar.NewReader(f)
    for {
        hdr, err := tr.Next()
        if err != nil { return false }
        if strings.TrimPrefix(strings.TrimPrefix(hdr.Name, "/"), "./") == want { return true }
    }
}

Type guard

if !tarContainsFile(tarPath, filePath) { return nil, fmt.Errorf("entry %q not present in %s", filePath, tarPath) }

Try / catch

data, err := FileDataFromTar(tarPath, filePath)
if err != nil {
    if strings.HasPrefix(err.Error(), "no file - ") {
        log.Warnf("entry %s missing from tar; listing entries for diagnosis", filePath)
        // fall back to scanning alternate layers or skip
        return nil, ErrEntryNotInTar
    }
    return err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/57b686b8f968c940. Report an issue: GitHub.