{"record":{"id":"b299f8b2da3bd89c","repo":"golang/go","slug":"reading-s-v","errorCode":null,"errorMessage":"reading %s: %v","messagePattern":"reading (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/imports/scan.go","lineNumber":62,"sourceCode":"func ScanFiles(files []string, tags map[string]bool) ([]string, []string, error) {\n\treturn scanFiles(files, tags, true)\n}\n\nfunc scanFiles(files []string, tags map[string]bool, explicitFiles bool) ([]string, []string, error) {\n\timports := make(map[string]bool)\n\ttestImports := make(map[string]bool)\n\tnumFiles := 0\nFiles:\n\tfor _, name := range files {\n\t\tr, err := fsys.Open(name)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\tvar list []string\n\t\tdata, err := ReadImports(r, false, &list)\n\t\tr.Close()\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"reading %s: %v\", name, err)\n\t\t}\n\n\t\t// import \"C\" is implicit requirement of cgo tag.\n\t\t// When listing files on the command line (explicitFiles=true)\n\t\t// we do not apply build tag filtering but we still do apply\n\t\t// cgo filtering, so no explicitFiles check here.\n\t\t// Why? Because we always have, and it's not worth breaking\n\t\t// that behavior now.\n\t\tfor _, path := range list {\n\t\t\tif path == `\"C\"` && !tags[\"cgo\"] && !tags[\"*\"] {\n\t\t\t\tcontinue Files\n\t\t\t}\n\t\t}\n\n\t\tif !explicitFiles && !ShouldBuild(data, tags) {\n\t\t\tcontinue\n\t\t}\n\t\tnumFiles++","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/imports/scan.go#L44-L80","documentation":"While scanning Go source files for import declarations (during go list, go build, go test, or imports.ScanDir/ScanFiles), the toolchain opens each .go file and calls ReadImports to parse it. If the read fails for any reason — I/O error, encoding problem, truncated content — the underlying error is wrapped with the filename in this message.","triggerScenarios":"A .go file passes the directory listing filter but fails when opened and read by fsys.Open + ReadImports. The file handle is closed before the error is returned. Causes include file permission changes between directory listing and read, non-UTF-8 encoding, truncated/corrupted files, or concurrent file deletion.","commonSituations":"Files modified or deleted by another process (IDE, formatter, linter) during a build. Permission restrictions on certain files in shared environments. Corrupted source files from a failed git checkout or network filesystem issue. NFS or SSHFS I/O errors.","solutions":["Check the file named in the error message — verify it exists and is readable (ls -la, cat).","Examine the underlying error (the %v portion) for the specific cause: permission denied, I/O error, EOF, etc.","If the file is corrupted or truncated, restore it from version control (git checkout -- <file>).","Re-run the build after fixing the file; transient filesystem errors may resolve on retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check file readability before invoking the build.\nfunc checkGoFilesReadable(dir string) error {\n    entries, err := os.ReadDir(dir)\n    if err != nil {\n        return err\n    }\n    for _, e := range entries {\n        if !strings.HasSuffix(e.Name(), \".go\") {\n            continue\n        }\n        f, err := os.Open(filepath.Join(dir, e.Name()))\n        if err != nil {\n            return fmt.Errorf(\"cannot open %s: %w\", e.Name(), err)\n        }\n        f.Close()\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// When using imports.ScanDir or go/packages programmatically:\nfiles, err := imports.ScanDir(dir, tags)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"reading\") {\n        // I/O or encoding error on a specific file\n        log.Printf(\"source file read failure: %v\", err)\n        // optionally: identify and report the problematic file, restore from VCS\n    }\n    return err\n}","preventionTips":["Ensure source files are readable before building.","Check for concurrent file modifications (formatters, IDEs) during builds.","Validate file integrity after git operations (git status, git diff).","Use go list to pre-validate packages before go build in CI."],"tags":["go","go-build","imports","scan","io","filesystem"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}