GoogleContainerTools/skaffold · error

stating file %q: %w

Error message

stating file %q: %w

What it means

Skaffold's SyncMap builds a map of source files to their destinations inside the container for file sync. Before walking, it stats each artifact's 'from' path in the workspace; if os.Stat fails (path missing or inaccessible), the stat error is wrapped with the absolute path and returned, aborting sync-map computation.

Source

Thrown at pkg/skaffold/docker/syncmap.go:74

}

// walkWorkspaceWithDestinations walks the given host directories and determines their
// location in the container. It returns a map of host path by container destination.
// Note: if you change this function, you might also want to modify `WalkWorkspace`.
func walkWorkspaceWithDestinations(workspace string, excludes []string, fts []FromTo) (map[string]string, error) {
	dockerIgnored, err := NewDockerIgnorePredicate(workspace, excludes)
	if err != nil {
		return nil, err
	}

	// Walk the workspace
	srcByDest := make(map[string]string)
	for _, ft := range fts {
		absFrom := filepath.Join(workspace, ft.From)

		fi, err := os.Stat(absFrom)
		if err != nil {
			return nil, fmt.Errorf("stating file %q: %w", absFrom, err)
		}

		switch mode := fi.Mode(); {
		case mode.IsDir():
			keepFile := func(path string, info walk.Dirent) (bool, error) {
				if info.IsDir() {
					if path == absFrom || util.IsEmptyDir(path) {
						return true, nil
					}
				}

				ignored, err := dockerIgnored(path, info)
				if err != nil {
					return false, err
				}

				return !ignored, nil
			}

View on GitHub (pinned to a1189de023)

Solutions

  1. Verify the sync 'from' path in skaffold.yaml exists relative to the artifact's build context (run ls <workspace>/<from>)
  2. Run skaffold from the directory containing the workspace, or fix the context field so workspace resolves correctly
  3. Check file/directory permissions (chmod/chown) if the path exists but stat fails with EACCES
  4. Remove stale sync entries pointing at deleted files

Example fix

// before (skaffold.yaml)
sync:
  manual:
    - src: 'src/**/*.ts'
      dest: ./app/src
// after — src path must exist under the build context:
// mkdir -p src && ensure *.ts files exist, or correct src: to the real directory
Defensive patterns

Strategy: validation

Validate before calling

for _, ft := range fts {
    absFrom := filepath.Join(workspace, ft.From)
    if _, err := os.Stat(absFrom); err != nil {
        return fmt.Errorf("sync source %q missing before SyncMap: %w", absFrom, err)
    }
}

Type guard

func syncSourceExists(workspace, from string) bool {
    _, err := os.Stat(filepath.Join(workspace, from))
    return err == nil
}

Try / catch

if err := SyncMap(fts, workspace); err != nil {
    var pErr *fs.PathError
    if errors.As(err, &pErr) && errors.Is(pErr.Err, fs.ErrNotExist) {
        log.Warnf("skipping sync: source %q missing", pErr.Path)
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling SyncMap for an artifact whose build context lists a sync rule with a 'from' path (ft.From) that does not exist or is unreadable under the workspace directory; os.Stat returns e.g. ENOENT, EACCES, or the path is a broken symlink.

Common situations: Typo in skaffold.yaml sync 'from' path; sync source deleted/renamed after config was written; running skaffold dev from the wrong working directory so the workspace path resolves incorrectly; permission-restricted checkout (CI running as non-root over root-owned files).

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/603b2a27d29ad195. Report an issue: GitHub.