{"record":{"id":"319aff271ffcea57","repo":"golangci/golangci-lint","slug":"file-s-not-found-w","errorCode":null,"errorMessage":"file %s not found: %w","messagePattern":"file (.+?) not found: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/configuration.go","lineNumber":98,"sourceCode":"\t// Module name.\n\tModule string `yaml:\"module\"`\n\n\t// Import to use.\n\tImport string `yaml:\"import,omitempty\"`\n\n\t// Version of the module.\n\t// Only for module available through a Go proxy.\n\tVersion string `yaml:\"version,omitempty\"`\n\n\t// Path to the local module.\n\t// Only for local module.\n\tPath string `yaml:\"path,omitempty\"`\n}\n\nfunc LoadConfiguration() (*Configuration, error) {\n\tconfigFilePath, err := findConfigurationFile()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"file %s not found: %w\", configFilePath, err)\n\t}\n\n\tfile, err := os.Open(configFilePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"file %s open: %w\", configFilePath, err)\n\t}\n\n\tdefer func() { _ = file.Close() }()\n\n\tvar cfg Configuration\n\n\terr = yaml.NewDecoder(file).Decode(&cfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"YAML decoding: %w\", err)\n\t}\n\n\treturn &cfg, nil\n}","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/configuration.go#L80-L116","documentation":"LoadConfiguration first calls findConfigurationFile to locate a config file in the current directory; if that returns an error, this wrapper reports 'file %s not found', embedding the (possibly empty) candidate path. It means no supported configuration file (e.g. YAML variants) could be found in the working directory.","triggerScenarios":"preRunE invoked LoadConfiguration while os.ReadDir(\".\") found no file whose extension matches a supported configuration format, or findConfigurationFile returned an error that is not a lookup failure — note the message would then be misleading since configFilePath is empty on error.","commonSituations":"Running the CLI in a directory without the config file instead of the project root, config file renamed to an unsupported extension (e.g. .conf, .yml.gz), file hidden as .tool.yaml when only *.yaml is scanned, or running from a different CWD in CI.","solutions":["cd to the project root (or the directory containing the config) before running the command","Create a configuration file with a supported extension/name in the current directory (e.g. config.yaml)","Rename the existing config to a supported filename/extension the finder recognizes","If the path in the message is empty, look at the wrapped error — the real failure is likely 'read directory' from findConfigurationFile, not a missing file"],"exampleFix":"// before\n$ cd /tmp && tool build   # no config here\n// after\n$ cd ~/projects/myapp && tool build   # directory containing config.yaml","handlingStrategy":"validation","validationCode":"supported := []string{\".yaml\", \".yml\", \".json\"}\nentries, err := os.ReadDir(\".\")\nif err != nil { return err }\nfound := false\nfor _, e := range entries {\n    if slices.Contains(supported, strings.ToLower(filepath.Ext(e.Name()))) { found = true; break }\n}\nif !found {\n    return fmt.Errorf(\"no config file with extensions %v in %s; run from the project root or create one\", supported, \".\")\n}","typeGuard":null,"tryCatchPattern":"cfg, err := LoadConfiguration()\nif err != nil {\n    var e *fs.PathError\n    if strings.Contains(err.Error(), \"not found\") {\n        log.Fatalf(\"no configuration file found in %s — cd to the project root or create config.yaml\", mustGetwd())\n    }\n    return err\n}","preventionTips":["Always run the CLI from the project root or set an explicit config path when supported","Use a recognized config filename/extension (e.g. config.yaml) committed to the repo","In CI, check out the repo before invoking the tool so the config is in CWD","Document supported config names so renames don't break discovery"],"tags":["go","config","file-not-found","cwd"],"backgroundTag":"config-file-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}