{"record":{"id":"f979d86bde8517d1","repo":"hashicorp/nomad","slug":"error-loading-s-s","errorCode":null,"errorMessage":"Error loading %s: %s","messagePattern":"Error loading (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/config.go","lineNumber":3271,"sourceCode":"}\n\n// LoadConfig loads the configuration at the given path, regardless if its a file or\n// directory. Called for each -config to build up the runtime config value. Do not apply any\n// default values, defaults should be added once in DefaultConfig\nfunc LoadConfig(path string) (*Config, error) {\n\tfi, err := os.Stat(path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif fi.IsDir() {\n\t\treturn LoadConfigDir(path)\n\t}\n\n\tcleaned := filepath.Clean(path)\n\tconfig, err := ParseConfigFile(cleaned)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error loading %s: %s\", cleaned, err)\n\t}\n\n\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","sourceCodeStart":3253,"sourceCodeEnd":3289,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/config.go#L3253-L3289","documentation":"LoadConfig(path) dispatches to LoadConfigDir for directories or ParseConfigFile for single files. When parsing a single config file fails, the error is wrapped as 'Error loading <path>: <reason>'. The wrapped message carries the actual parse/validation failure from ParseConfigFile (e.g. HCL/JSON syntax errors).","triggerScenarios":"consul agent -config-file=<path> where path is a file whose contents fail ParseConfigFile — invalid HCL/JSON syntax, unknown keys, wrong types, or unreadable content.","commonSituations":"Typos in JSON/HCL config files, mixing JSON syntax into .hcl files, trailing commas in JSON, or passing a file that contains config from another tool.","solutions":["Read the wrapped underlying error after the colon — it names the exact parse problem and line","Validate the file with hclfmt or a JSON linter","Convert JSON configs to HCL carefully; they are not interchangeable syntactically","Confirm the path is the intended file and is readable"],"exampleFix":"// before (config.json)\n{\"datacenter\": \"dc1\",,}\n// after\n{\"datacenter\": \"dc1\"}","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(path); err == nil && !fi.IsDir() {\n    if err := validateConfigFile(path); err != nil {\n        return fmt.Errorf(\"config file %s invalid before load: %w\", path, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"config, err := agentcfg.LoadConfig(path)\nif err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) { return perr }\n    return fmt.Errorf(\"load %s: %w\", path, err)\n}","preventionTips":["Run consul validate on all config files in CI","Keep JSON and HCL files syntactically separate","Format configs with hclfmt / jq before deploy","Make one config change per deploy to isolate breakage"],"tags":["config","consul","hcl","file-loading"],"backgroundTag":"config-file-parse-error","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"}