hashicorp/nomad · error

error creating file: %w

Error message

error creating file: %w

What it means

During tar extraction, after removing any prior entry, Nomad calls os.Create on the destination file path. This error is returned when file creation fails, typically because the parent directory does not exist or lacks write permission.

Source

Thrown at client/allocwatcher/alloc_watcher.go:653

					return fmt.Errorf("error evaluating symlink: %w", err)
				} else if escapes {
					return fmt.Errorf("archive contains symlink that escapes alloc dir")
				}
			}

			continue
		}
		// If the header is a file, we write to a file
		if hdr.Typeflag == tar.TypeReg {
			fPath := filepath.Join(dest, hdr.Name)
			if _, err := os.Lstat(fPath); err == nil {
				if err := os.Remove(fPath); err != nil {
					return fmt.Errorf("error removing existing file: %w", err)
				}
			}
			f, err := os.Create(fPath)
			if err != nil {
				return fmt.Errorf("error creating file: %w", err)
			}

			// Setting the permissions of the file as the origin.
			if err := f.Chmod(os.FileMode(hdr.Mode)); err != nil {
				f.Close()
				return fmt.Errorf("error chmoding file %w", err)
			}

			// Can't change owner if not root or on Windows.
			if euid == 0 {
				if err := f.Chown(hdr.Uid, hdr.Gid); err != nil {
					f.Close()
					return fmt.Errorf("error chowning file %w", err)
				}
			}

			// We write in chunks so that we can test if the client
			// is still alive

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Verify the archive contains directory entries before the files inside them
  2. Check free disk space (ENOSPC) on the destination node
  3. Fix write permissions/ownership of the alloc dir for the Nomad client user
  4. Clean stale/partial extraction state and retry the migration
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight checks before migration:
// free disk space (syscall.Statfs) and write access to the destination (os.WriteFile probe)

Try / catch

if err := watcher.Wait(ctx); err != nil {
    if strings.Contains(err.Error(), "error creating file") {
        if errors.Is(err, syscall.ENOSPC) { alertDiskFull(); return err }
        os.RemoveAll(dest)
        return retryMigration(ctx, alloc)
    }
    return err
}

Prevention

When it happens

Trigger: streamAllocDir processes a tar.TypeReg header and os.Create(filepath.Join(dest, hdr.Name)) returns an error (ENOENT missing parent dir, EACCES, ENOSPC).

Common situations: Archive lists a file before its parent directory entry; disk full on the destination node; permission mismatch after running the client as a different user; path collisions with an existing directory.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/413439b9ffcf6e00. Report an issue: GitHub.