{"record":{"id":"861d07933050ab96","repo":"golang/go","slug":"internal-error-main-module-version-is-not-allowed","errorCode":null,"errorMessage":"internal error: main module version is not allowed: %w","messagePattern":"internal error: main module version is not allowed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/query.go","lineNumber":217,"sourceCode":"\nfunc queryProxy(ld *Loader, ctx context.Context, proxy, path, query, current string, allowed AllowedFunc, reuse map[module.Version]*modinfo.ModulePublic) (*modfetch.RevInfo, error) {\n\tctx, span := trace.StartSpan(ctx, \"modload.queryProxy \"+path+\" \"+query)\n\tdefer span.Done()\n\n\tif current != \"\" && current != \"none\" && !gover.ModIsValid(path, current) {\n\t\treturn nil, fmt.Errorf(\"invalid previous version %v@%v\", path, current)\n\t}\n\tif cfg.BuildMod == \"vendor\" {\n\t\treturn nil, errQueryDisabled\n\t}\n\tif allowed == nil {\n\t\tallowed = func(context.Context, module.Version) error { return nil }\n\t}\n\n\tif ld.MainModules.Contains(path) && (query == \"upgrade\" || query == \"patch\") {\n\t\tm := module.Version{Path: path}\n\t\tif err := allowed(ctx, m); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"internal error: main module version is not allowed: %w\", err)\n\t\t}\n\t\treturn &modfetch.RevInfo{Version: m.Version}, nil\n\t}\n\n\tif path == \"std\" || path == \"cmd\" {\n\t\treturn nil, fmt.Errorf(\"can't query specific version (%q) of standard-library module %q\", query, path)\n\t}\n\n\trepo, err := lookupRepo(ld, ctx, proxy, path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif old := reuse[module.Version{Path: path, Version: query}]; old != nil {\n\t\tif err := checkReuseRepo(ctx, repo, path, query, old.Origin); err == nil {\n\t\t\tinfo := &modfetch.RevInfo{\n\t\t\t\tVersion: old.Version,\n\t\t\t\tOrigin:  old.Origin,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/query.go#L199-L235","documentation":"Internal invariant error inside queryProxy: the queried path is a main-module path with an 'upgrade'/'patch' query, but the supplied AllowedFunc rejected the main module's version. Because main-module versions are by definition present and not subject to external allow/deny rules, a rejection here indicates a bug in the caller's AllowedFunc or in toolchain wiring.","triggerScenarios":"Programmatically calling queryProxy with an AllowedFunc that returns a non-nil error for the main module, or a toolchain path that injects an over-restrictive allow-list for main-module paths.","commonSituations":"Almost never seen by end users; appears in custom tooling built on cmd/go/internal/modload that supplies a buggy AllowedFunc, or when retraction/version-allow logic is misconfigured internally.","solutions":["If you maintain a tool calling this API, ensure AllowedFunc permits (returns nil) for main-module versions.","As an end user seeing this, it indicates a Go toolchain bug — report it at https://go.dev/issue with the reproduction.","Retry with GOFLAGS=-mod=mod and a clean cache to rule out a transient state corruption."],"exampleFix":"// before (custom caller)\nallowed := func(ctx, m) error { return errors.New(\"no\") }\nqueryProxy(..., \"upgrade\", ..., allowed)\n// error: internal error: main module version is not allowed: no\n\n// after\nallowed := func(ctx, m) error {\n    if ld.MainModules.Contains(m.Path) { return nil }\n    return checkExternal(m)\n}","handlingStrategy":"validation","validationCode":"// In custom tooling, default AllowedFunc to permit main-module paths:\n//   allowed := func(ctx context.Context, m module.Version) error {\n//       if ld.MainModules.Contains(m.Path) { return nil }\n//       return externalCheck(ctx, m)\n//   }","typeGuard":"func safeAllowed(ld *Loader, external AllowedFunc) AllowedFunc {\n    return func(ctx context.Context, m module.Version) error {\n        if ld.MainModules.Contains(m.Path) { return nil }\n        if external == nil { return nil }\n        return external(ctx, m)\n    }\n}","tryCatchPattern":null,"preventionTips":["Always let AllowedFunc return nil for main-module paths.","Unit-test AllowedFunc against the main module before wiring it into queryProxy.","Log AllowFunc rejections in tooling to catch over-broad rules."],"tags":["go-modules","internal-error","query","allowed-func"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}