{"record":{"id":"b57e82c75f286869","repo":"golangci/golangci-lint","slug":"failed-to-expand-configuration-path","errorCode":null,"errorMessage":"failed to expand configuration path","messagePattern":"failed to expand configuration path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/base_loader.go","lineNumber":94,"sourceCode":"\t} else {\n\t\tl.setupConfigFileSearch()\n\t}\n\n\treturn nil\n}\n\nfunc (l *BaseLoader) evaluateOptions() (string, error) {\n\tif l.opts.NoConfig && l.opts.Config != \"\" {\n\t\treturn \"\", errors.New(\"can't combine option --config and --no-config\")\n\t}\n\n\tif l.opts.NoConfig {\n\t\treturn \"\", errConfigDisabled\n\t}\n\n\tconfigFile, err := homedir.Expand(l.opts.Config)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"failed to expand configuration path\")\n\t}\n\n\treturn configFile, nil\n}\n\nfunc (l *BaseLoader) setupConfigFileSearch() {\n\tl.viper.SetConfigName(\".golangci\")\n\n\tconfigSearchPaths := l.getConfigSearchPaths()\n\n\tl.log.Infof(\"Config search paths: %s\", configSearchPaths)\n\n\tfor _, p := range configSearchPaths {\n\t\tl.viper.AddConfigPath(p)\n\t}\n}\n\nfunc (l *BaseLoader) getConfigSearchPaths() []string {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/base_loader.go#L76-L112","documentation":"After the mutual-exclusion check, evaluateOptions expands a leading `~/` in the --config path via homedir.Expand. If expansion fails (bad home-directory resolution), the loader returns this error instead of proceeding with an unusable path.","triggerScenarios":"Passing a config path starting with `~` while the HOME environment variable is unset/empty, or any path homedir.Expand cannot resolve on the current OS/user context.","commonSituations":"CI containers without HOME set (e.g. minimal Docker images, cron jobs with a stripped environment); running under service accounts with no home directory.","solutions":["Set the HOME environment variable to a readable directory.","Replace `~` in the --config value with the absolute path (e.g. /root/.golangci.yml).","In code, validate/expand the path with os.UserHomeDir or filepath.Abs before setting opts.Config."],"exampleFix":"// before\ngolangci-lint run --config ~/.golangci.yml   # HOME unset in CI\n\n// after\nexport HOME=/root\ngolangci-lint run --config /root/.golangci.yml","handlingStrategy":"validation","validationCode":"const path = require('path');\nfunction resolveConfig(p) {\n  if (p.startsWith('~')) {\n    const home = process.env.HOME;\n    if (!home) throw new Error('HOME is not set; cannot expand ~ in config path');\n    return path.join(home, p.slice(1));\n  }\n  return p;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use absolute config paths in CI scripts and Dockerfiles.","Ensure HOME is set in container/cron environments.","Check the file exists (fs.existsSync / test -f) before invoking the linter."],"tags":["filesystem","configuration","path-expansion"],"backgroundTag":"home-dir-expansion-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}