hashicorp/nomad · error

Unable to tar files - %v

Error message

Unable to tar files - %v

What it means

TarCZF builds a gzip-compressed tar archive of the collected debug bundle directory. Before creating the archive it stats the source directory; if os.Stat fails (path missing or unreadable) it aborts with this message. The bundle could not be packaged because the directory of collected files does not exist at the expected path.

Source

Thrown at command/operator_debug.go:1779

}

func (c *OperatorDebugCommand) verboseOut(out string) {
	if c.verbose {
		c.Ui.Output(out)
	}
}

func (c *OperatorDebugCommand) verboseOutf(format string, a ...any) {
	c.verboseOut(fmt.Sprintf(format, a...))
}

// TarCZF like the tar command, recursively builds a gzip compressed tar
// archive from a directory. If not empty, all files in the bundle are prefixed
// with the target path.
func TarCZF(archive string, src, target string) error {
	// ensure the src actually exists before trying to tar it
	if _, err := os.Stat(src); err != nil {
		return fmt.Errorf("Unable to tar files - %v", err.Error())
	}

	// create the archive
	fh, err := os.Create(archive)
	if err != nil {
		return err
	}
	defer fh.Close()

	zz := gzip.NewWriter(fh)
	defer zz.Close()

	tw := tar.NewWriter(zz)
	defer tw.Close()

	// tar
	return filepath.Walk(src, func(file string, fi os.FileInfo, err error) error {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Verify the source directory path exists and is readable: ls <src>
  2. Check that the -output parent directory is writable before running debug
  3. Re-run `nomad operator debug` to recreate the collection directory
  4. Fix the code to wrap the cause: fmt.Errorf("Unable to tar files - %w", err) instead of err.Error()

Example fix

// before
return fmt.Errorf("Unable to tar files - %v", err.Error())
// after
return fmt.Errorf("unable to tar files: %w", err)
Defensive patterns

Strategy: validation

Validate before calling

src := "path/to/bundle-dir"
if fi, err := os.Stat(src); err != nil {
    return fmt.Errorf("bundle source missing: %w", err)
} else if !fi.IsDir() {
    return fmt.Errorf("%s is not a directory", src)
}

Try / catch

if err := TarCZF(archive, src, target); err != nil {
    if errors.Is(err, fs.ErrNotExist) {
        log.Printf("bundle dir %s missing; rerun collection", src)
    }
    return err
}

Prevention

When it happens

Trigger: os.Stat(src) fails when TarCZF is invoked at the end of `nomad operator debug` — the temporary/collected bundle directory was never created, was deleted, or is not accessible.

Common situations: Output directory removed between collection and tarring, wrong -output path, sandboxed environments (containers, read-only mounts) where the working directory is not writable, or permission revocation mid-run.

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 hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/4f65f4cadeb68a28. Report an issue: GitHub.