{"record":{"id":"91f9b3361bfe1485","repo":"hashicorp/nomad","slug":"configuration-path-must-be-a-directory-s","errorCode":null,"errorMessage":"configuration path must be a directory: %s","messagePattern":"configuration path must be a directory: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/config.go","lineNumber":3292,"sourceCode":"\tconfig.Files = append(config.Files, cleaned)\n\treturn config, nil\n}\n\n// LoadConfigDir loads all the configurations in the given directory\n// in alphabetical order.\nfunc LoadConfigDir(dir string) (*Config, error) {\n\tf, err := os.Open(dir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer f.Close()\n\n\tfi, err := f.Stat()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !fi.IsDir() {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"configuration path must be a directory: %s\", dir)\n\t}\n\n\tvar files []string\n\terr = nil\n\tfor err != io.EOF {\n\t\tvar fis []os.FileInfo\n\t\tfis, err = f.Readdir(128)\n\t\tif err != nil && err != io.EOF {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tfor _, fi := range fis {\n\t\t\t// Ignore directories\n\t\t\tif fi.IsDir() {\n\t\t\t\tcontinue\n\t\t\t}\n","sourceCodeStart":3274,"sourceCodeEnd":3310,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/config.go#L3274-L3310","documentation":"LoadConfigDir requires the given path to be a directory containing config files. If the Stat call succeeds but the path is a regular file (or other non-directory), LoadConfigDir returns this error directly instead of parsing it.","triggerScenarios":"Calling LoadConfigDir(path) — or consul agent -config-dir=<path> — with a path that points to a single file rather than a directory.","commonSituations":"Confusing -config-dir with -config-file, shell variable expansion pointing at a file, or symlinks resolving to a file after restructuring config layout.","solutions":["Use -config-file (LoadConfig) for a single file and -config-dir (LoadConfigDir) for a directory","Pass the directory containing your .json/.hcl config files","Verify the path with ls -la / os.Stat before launching","Fix scripts where a variable may expand to either a file or directory"],"exampleFix":"// before\nconsul agent -config-dir=/etc/consul.d/config.hcl\n// after\nconsul agent -config-dir=/etc/consul.d/","handlingStrategy":"type-guard","validationCode":"fi, err := os.Stat(dir)\nif err != nil { return err }\nif !fi.IsDir() {\n    return fmt.Errorf(\"%s is a file; use -config-file instead\", dir)\n}","typeGuard":"func isConfigDir(path string) bool {\n    fi, err := os.Stat(path)\n    return err == nil && fi.IsDir()\n}","tryCatchPattern":"if !isConfigDir(dir) {\n    cfg, err = agentcfg.LoadConfig(dir) // single-file path\n} else {\n    cfg, err = agentcfg.LoadConfigDir(dir)\n}\nif err != nil { return err }","preventionTips":["Match the CLI flag to the path type: -config-file vs -config-dir","Stat paths in deploy scripts before invoking Consul","Resolve symlinks to know what they ultimately point to"],"tags":["config","consul","file-loading","path"],"backgroundTag":"wrong-path-type","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"}