{"record":{"id":"b27c4069f7491146","repo":"golang/go","slug":"corrupt-index","errorCode":null,"errorMessage":"corrupt index","messagePattern":"corrupt index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/read.go","lineNumber":247,"sourceCode":"\t\t\t// But double check on Windows that we haven't opened the file yet,\n\t\t\t// because once mmap opens the file, we can't close it, and\n\t\t\t// Windows won't let us open an already opened file.\n\t\t\tdata = indexPackage(modroot, pkgdir)\n\t\t\tif runtime.GOOS != \"windows\" || !opened {\n\t\t\t\tif err = cache.PutBytes(cache.Default(), id, data); err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpkg, err := packageFromBytes(modroot, data)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn pkg, nil\n\t})\n}\n\nvar errCorrupt = errors.New(\"corrupt index\")\n\n// protect marks the start of a large section of code that accesses the index.\n// It should be used as:\n//\n//\tdefer unprotect(protect, &err)\n//\n// It should not be used for trivial accesses which would be\n// dwarfed by the overhead of the defer.\nfunc protect() bool {\n\treturn debug.SetPanicOnFault(true)\n}\n\nvar isTest = false\n\n// unprotect marks the end of a large section of code that accesses the index.\n// It should be used as:\n//\n//\tdefer unprotect(protect, &err)","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/read.go#L229-L265","documentation":"The module index file is malformed or unreadable: packageFromBytes or the surrounding fault-protected read failed. protect() enables debug.SetPanicOnFault and the recover translates a fault or parse failure into errCorrupt (\"corrupt index\"), indicating the on-disk index cannot be trusted.","triggerScenarios":"Reading the index file triggers a SIGSEGV (unmapped page) recovered by protect(), or the bytes fail to parse into an IndexPackage via packageFromBytes.","commonSituations":"Disk corruption; an index write interrupted by a crash or kill; partially-cloned GOMODCACHE; mismatched go versions writing incompatible index formats to a shared cache; truncated file from ENOSPC during write.","solutions":["Run `go clean -modcache` to delete the cache and let the index rebuild cleanly.","Ensure all toolchains sharing the cache are at compatible go versions.","If corruption recurs, verify disk health and that GOMODCACHE is not on an unreliable network/overlay filesystem."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// On errors.Is(err, errCorrupt) (or the \"corrupt index\" message),\n// run `go clean -modcache` and retry; the index rebuilds on next use.","preventionTips":["Do not share GOMODCACHE across incompatible go versions.","Keep GOMODCACHE on reliable local storage, not flaky network/overlay filesystems."],"tags":["go","modules","index","corruption","cache"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}