{"record":{"id":"4f65f4cadeb68a28","repo":"hashicorp/nomad","slug":"unable-to-tar-files-v","errorCode":null,"errorMessage":"Unable to tar files - %v","messagePattern":"Unable to tar files - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":1779,"sourceCode":"}\n\nfunc (c *OperatorDebugCommand) verboseOut(out string) {\n\tif c.verbose {\n\t\tc.Ui.Output(out)\n\t}\n}\n\nfunc (c *OperatorDebugCommand) verboseOutf(format string, a ...any) {\n\tc.verboseOut(fmt.Sprintf(format, a...))\n}\n\n// TarCZF like the tar command, recursively builds a gzip compressed tar\n// archive from a directory. If not empty, all files in the bundle are prefixed\n// with the target path.\nfunc TarCZF(archive string, src, target string) error {\n\t// ensure the src actually exists before trying to tar it\n\tif _, err := os.Stat(src); err != nil {\n\t\treturn fmt.Errorf(\"Unable to tar files - %v\", err.Error())\n\t}\n\n\t// create the archive\n\tfh, err := os.Create(archive)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer fh.Close()\n\n\tzz := gzip.NewWriter(fh)\n\tdefer zz.Close()\n\n\ttw := tar.NewWriter(zz)\n\tdefer tw.Close()\n\n\t// tar\n\treturn filepath.Walk(src, func(file string, fi os.FileInfo, err error) error {\n","sourceCodeStart":1761,"sourceCodeEnd":1797,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L1761-L1797","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the source directory path exists and is readable: ls <src>","Check that the -output parent directory is writable before running debug","Re-run `nomad operator debug` to recreate the collection directory","Fix the code to wrap the cause: fmt.Errorf(\"Unable to tar files - %w\", err) instead of err.Error()"],"exampleFix":"// before\nreturn fmt.Errorf(\"Unable to tar files - %v\", err.Error())\n// after\nreturn fmt.Errorf(\"unable to tar files: %w\", err)","handlingStrategy":"validation","validationCode":"src := \"path/to/bundle-dir\"\nif fi, err := os.Stat(src); err != nil {\n    return fmt.Errorf(\"bundle source missing: %w\", err)\n} else if !fi.IsDir() {\n    return fmt.Errorf(\"%s is not a directory\", src)\n}","typeGuard":null,"tryCatchPattern":"if err := TarCZF(archive, src, target); err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        log.Printf(\"bundle dir %s missing; rerun collection\", src)\n    }\n    return err\n}","preventionTips":["Confirm the collected bundle directory exists before archiving","Do not clean temp dirs concurrently with the debug run","Use absolute paths for -output to avoid cwd assumptions","Run in environments with a writable working directory (avoid read-only mounts)"],"tags":["filesystem","archive","debug-bundle"],"backgroundTag":"file-not-found","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}