{"record":{"id":"f55bdca4475929db","repo":"golang/go","slug":"import-q-unknown-compiler-q","errorCode":null,"errorMessage":"import %q: unknown compiler %q","messagePattern":"import %q: unknown compiler %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/read.go","lineNumber":397,"sourceCode":"var installgorootAll = godebug.New(\"installgoroot\").Value() == \"all\"\n\n// Import is the equivalent of build.Import given the information in Module.\nfunc (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *build.Package, err error) {\n\tdefer unprotect(protect(), &err)\n\n\tctxt := (*Context)(&bctxt)\n\n\tp = &build.Package{}\n\n\tp.ImportPath = \".\"\n\tp.Dir = filepath.Join(rp.modroot, rp.dir)\n\n\tvar pkgerr error\n\tswitch ctxt.Compiler {\n\tcase \"gccgo\", \"gc\":\n\tdefault:\n\t\t// Save error for end of function.\n\t\tpkgerr = fmt.Errorf(\"import %q: unknown compiler %q\", p.Dir, ctxt.Compiler)\n\t}\n\n\tif p.Dir == \"\" {\n\t\treturn p, fmt.Errorf(\"import %q: import of unknown directory\", p.Dir)\n\t}\n\n\t// goroot and gopath\n\tinTestdata := func(sub string) bool {\n\t\tsub = filepath.ToSlash(sub)\n\t\treturn strings.Contains(sub, \"/testdata/\") || strings.HasSuffix(sub, \"/testdata\") || str.HasPathPrefix(sub, \"testdata\")\n\t}\n\tvar pkga string\n\tif !inTestdata(rp.dir) {\n\t\t// In build.go, p.Root should only be set in the non-local-import case, or in\n\t\t// GOROOT or GOPATH. Since module mode only calls Import with path set to \".\"\n\t\t// and the module index doesn't apply outside modules, the GOROOT case is\n\t\t// the only case where p.Root needs to be set.\n\t\tif ctxt.GOROOT != \"\" && str.HasFilePathPrefix(p.Dir, cfg.GOROOTsrc) && p.Dir != cfg.GOROOTsrc {","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/read.go#L379-L415","documentation":"Returned (deferred to end of Import) by IndexPackage.Import when ctxt.Compiler is neither 'gc' nor 'gccgo'. The build.Context.Compiler field selects which compiler's conventions the index should follow; an unknown value means the index cannot decide import paths, archive names, or install roots, so the import is rejected.","triggerScenarios":"Constructing a custom build.Context with an experimental or typo'd Compiler string (e.g. 'gcc', 'tinygo', 'llgo') and passing it to IndexPackage.Import. The error is stored in pkgerr and surfaced after Import finishes its other work.","commonSituations":"Third-party tooling sets context.Compiler to a non-standard value; user typos 'gcc' for 'gccgo'; integrating the module index with an unsupported Go compiler fork.","solutions":["Set context.Compiler to 'gc' (standard) or 'gccgo' before calling Import.","For non-standard compilers, do not use the module index path; fall back to go/build.Import directly.","Check for typo'd compiler names when constructing the build context."],"exampleFix":"// before\nctx := build.Default\nctx.Compiler = \"gcc\"\np, err := idxPkg.Import(ctx, 0)\n// after\nctx.Compiler = \"gccgo\"","handlingStrategy":"validation","validationCode":"// Validate Compiler before Import.\nfunc supportedCompiler(c string) bool {\n    return c == \"gc\" || c == \"gccgo\"\n}\n\n// usage\nctx := build.Default\nif !supportedCompiler(ctx.Compiler) {\n    return fmt.Errorf(\"unsupported compiler %q; use gc or gccgo\", ctx.Compiler)\n}\npkg, err := idxPkg.Import(ctx, 0)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set build.Context.Compiler to non-standard values without a fallback path.","Spell the gccgo compiler name exactly: 'gccgo' (not 'gcc')."],"tags":["build-context","compiler","module-index","configuration"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}