{"record":{"id":"63550bac60937c8e","repo":"golang/go","slug":"w-q-in-s","errorCode":null,"errorMessage":"%w %q in:\n\t%s","messagePattern":"%w %q in:\n\t(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/read.go","lineNumber":832,"sourceCode":"\tmodroot string\n\n\t// Source files\n\tsourceFiles []*sourceFile\n}\n\nvar errCannotFindPackage = errors.New(\"cannot find package\")\n\n// Package and returns finds the package with the given path (relative to the module root).\n// If the package does not exist, Package returns an IndexPackage that will return an\n// appropriate error from its methods.\nfunc (m *Module) Package(path string) *IndexPackage {\n\tdefer unprotect(protect(), nil)\n\n\ti, ok := sort.Find(m.n, func(i int) int {\n\t\treturn strings.Compare(path, m.pkgDir(i))\n\t})\n\tif !ok {\n\t\treturn &IndexPackage{error: fmt.Errorf(\"%w %q in:\\n\\t%s\", errCannotFindPackage, path, filepath.Join(m.modroot, path))}\n\t}\n\treturn m.pkg(i)\n}\n\n// pkg returns the i'th IndexPackage in m.\nfunc (m *Module) pkg(i int) *IndexPackage {\n\tr := m.d.readAt(m.pkgOff(i))\n\tp := new(IndexPackage)\n\tif errstr := r.string(); errstr != \"\" {\n\t\tp.error = errors.New(errstr)\n\t}\n\tp.dir = r.string()\n\tp.sourceFiles = make([]*sourceFile, r.int())\n\tfor i := range p.sourceFiles {\n\t\tp.sourceFiles[i] = &sourceFile{\n\t\t\td:   m.d,\n\t\t\tpos: r.int(),\n\t\t}","sourceCodeStart":814,"sourceCodeEnd":850,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/read.go#L814-L850","documentation":"Sentinel-wrapped 'package not found' error from (*Module).Package. The method binary-searches the module's package directory table via sort.Find; if the requested path is not present, it returns an IndexPackage pre-populated with an error that wraps errCannotFindPackage (the %w). The message format is `<sentinel> <path> in:\n\t<abs path>`, so errors.Is(err, errCannotFindPackage) succeeds.","triggerScenarios":"Calling (*Module).Package(path) where path does not match any directory recorded in the module index — e.g. a typo'd import path, a subpackage that has no .go files, or a path that lives in a different module.","commonSituations":"Importing a path that doesn't exist under the module root; refactoring that moved a package; case-sensitivity mismatches on case-insensitive filesystems; querying the wrong module index.","solutions":["Verify the path exists on disk under the module root with `ls <modroot>/<path>`.","Check spelling and case of the import path; Go import paths are case-sensitive.","Use (*Module).Walk to enumerate the exact package paths the index knows about.","If the package should exist, ensure it contains at least one non-test .go file so the indexer records it."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Check existence before calling Package by enumerating known dirs via Walk.\nfunc packageExists(m *modindex.Module, path string) bool {\n    found := false\n    m.Walk(func(p string) {\n        if p == path { found = true }\n    })\n    return found\n}","typeGuard":"// Distinguish the sentinel from other IndexPackage errors.\nimport \"errors\"\n\nfunc isPackageNotFound(err error) bool {\n    return errors.Is(err, modindex.ErrCannotFindPackage)\n}","tryCatchPattern":null,"preventionTips":["Cache the set of valid package paths via Module.Walk before issuing many Package calls.","Treat not-found as a logic error in the caller — fix the path, do not retry blindly."],"tags":["module-index","import","not-found"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}