{"record":{"id":"dcc87bfa9a1db20f","repo":"golangci/golangci-lint","slug":"can-t-open-file-s-w","errorCode":null,"errorMessage":"can't open file %s: %w","messagePattern":"can't open file (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/golinters/lll/lll.go","lineNumber":60,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc getLLLIssuesForFile(pass *analysis.Pass, file *ast.File, maxLineLen int, tabSpaces string) error {\n\tposition, isGoFile := goanalysis.GetGoFilePosition(pass, file)\n\tif !isGoFile {\n\t\treturn nil\n\t}\n\n\tnonAdjPosition := pass.Fset.PositionFor(file.Pos(), false)\n\n\tf, err := os.Open(position.Filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't open file %s: %w\", position.Filename, err)\n\t}\n\n\tdefer f.Close()\n\n\tft := pass.Fset.File(file.Pos())\n\n\tlineNumber := 0\n\tmultiImportEnabled := false\n\n\tscanner := bufio.NewScanner(f)\n\tfor scanner.Scan() {\n\t\tlineNumber++\n\n\t\tline := scanner.Text()\n\t\tline = strings.ReplaceAll(line, \"\\t\", tabSpaces)\n\n\t\tif strings.HasPrefix(line, goCommentDirectivePrefix) {\n\t\t\tcontinue","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/golinters/lll/lll.go#L42-L78","documentation":"When computing line-length (lll) issues, golangci-lint reopens each source file from disk (os.Open on position.Filename). If the file can't be opened — missing, permission denied, or path issues — getLLLIssuesForFile wraps the OS error with this message and aborts the linter run.","triggerScenarios":"The file referenced by the AST position no longer exists or isn't readable at lint time: deleted/renamed between generation and lint, unreadable permissions, symlink to nonexistent target, running in a container without the file mounted.","commonSituations":"Generated code files removed before linting, read-only or root-owned checkout (permission denied), linting outside the module where relative paths break, cgo/generated files with unusual paths.","solutions":["Check the file exists and is readable: ls -l <file> and fix permissions (chmod/chown) or restore the file (git checkout -- <file>)","Regenerate deleted generated files before running golangci-lint","Run golangci-lint from the module root so relative paths resolve","Check symlink targets exist; fix or remove broken symlinks"],"exampleFix":"# before\n$ golangci-lint run\n# can't open file /path/to/generated_gen.go: no such file or directory\n# after\n$ make generate   # regenerate the missing file\n$ golangci-lint run","handlingStrategy":"try-catch","validationCode":"import fs from 'node:fs'\nfor (const f of filesToLint) {\n  try { fs.accessSync(f, fs.constants.R_OK) } catch (e) {\n    throw new Error(`lll precondition failed: ${f} not readable (${e.message})`)\n  }\n}","typeGuard":"const isReadableFile = (p) => { try { return fs.statSync(p).isFile() && !!(fs.accessSync(p, fs.constants.R_OK) ?? true) } catch { return false } }","tryCatchPattern":"try {\n  await runGolangciLint(['--enable=lll'])\n} catch (e) {\n  if (/can't open file .*: /.test(String(e))) {\n    // recover file (git checkout / regenerate) and retry once\n    await restoreMissingFiles(); await runGolangciLint(['--enable=lll'])\n  } else { throw e }\n}","preventionTips":["Regenerate generated files before linting (make generate in CI)","Run golangci-lint from the module root with the full checkout present","Check file permissions and symlink targets in containerized lint jobs","Restore deleted files with git checkout before re-running lint"],"tags":["golangci-lint","lll","filesystem"],"backgroundTag":"file-open-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}