{"record":{"id":"67c2ea33fa213ca3","repo":"hashicorp/nomad","slug":"failed-to-list-directory-s","errorCode":null,"errorMessage":"Failed to list directory %s","messagePattern":"Failed to list directory (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/fmt.go","lineNumber":203,"sourceCode":"\t\t\t\t\tf.appendError(fmt.Errorf(\"Failed to open file %s: %w\", path, err))\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tf.processFile(path, fp)\n\n\t\t\t\tfp.Close()\n\t\t\t} else {\n\t\t\t\tf.appendError(fmt.Errorf(\"Only .nomad and .hcl files can be processed using nomad fmt\"))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (f *FormatCommand) processDir(path string) {\n\tentries, err := os.ReadDir(path)\n\tif err != nil {\n\t\tf.appendError(fmt.Errorf(\"Failed to list directory %s\", path))\n\t\treturn\n\t}\n\n\tfor _, entry := range entries {\n\t\tname := entry.Name()\n\t\tsubpath := filepath.Join(path, name)\n\n\t\tif entry.IsDir() {\n\t\t\tif f.recursive {\n\t\t\t\tf.processDir(subpath)\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\n\t\tinfo, err := entry.Info()\n\t\tif err != nil {\n\t\t\tf.appendError(err)","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/fmt.go#L185-L221","documentation":"processDir wraps os.ReadDir; if the directory cannot be read (missing path, not a directory, permission denied), the underlying error is discarded and a generic 'Failed to list directory <path>' is appended.","triggerScenarios":"`nomad fmt ./dir` where ./dir does not exist, is a file, or the process lacks read permission on it.","commonSituations":"Typo in the directory path passed to nomad fmt; running as a user without permissions on a shared mount; passing a single file path where fmt expects to recurse a directory.","solutions":["Verify the directory path exists with ls before running nomad fmt","Check filesystem permissions on the directory (ls -ld)","Confirm the argument is a directory, not a file","Run with a user that has read access to the path"],"exampleFix":"// before\nnomad fmt ./jobss   # typo\n// after\nnomad fmt ./jobs","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(path); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"%s is not a readable directory\", path)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the path exists and is a directory before running","Check read permissions (ls -ld)","Avoid typos by tab-completing paths"],"tags":["cli","filesystem","permissions","io"],"backgroundTag":"directory-read-failed","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"}