{"record":{"id":"ef6df7251c8dcce8","repo":"grpc-ecosystem/grpc-gateway","slug":"package-name-s-is-already-taken-use-another-alia","errorCode":null,"errorMessage":"package name %s is already taken. Use another alias","messagePattern":"package name (.+?) is already taken\\. Use another alias","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/descriptor/registry.go","lineNumber":490,"sourceCode":"func (r *Registry) SetRecursiveDepth(count int) {\n\tr.recursiveDepth = count\n}\n\n// GetRecursiveDepth returns the max recursion count\nfunc (r *Registry) GetRecursiveDepth() int {\n\treturn r.recursiveDepth\n}\n\n// ReserveGoPackageAlias reserves the unique alias of go package.\n// If succeeded, the alias will be never used for other packages in generated go files.\n// If failed, the alias is already taken by another package, so you need to use another\n// alias for the package in your go files.\nfunc (r *Registry) ReserveGoPackageAlias(alias, pkgpath string) error {\n\tif taken, ok := r.pkgAliases[alias]; ok {\n\t\tif taken == pkgpath {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"package name %s is already taken. Use another alias\", alias)\n\t}\n\tr.pkgAliases[alias] = pkgpath\n\treturn nil\n}\n\n// GetAllFQMNs returns a list of all FQMNs\nfunc (r *Registry) GetAllFQMNs() []string {\n\tkeys := make([]string, 0, len(r.msgs))\n\tfor k := range r.msgs {\n\t\tkeys = append(keys, k)\n\t}\n\treturn keys\n}\n\n// GetAllFQENs returns a list of all FQENs\nfunc (r *Registry) GetAllFQENs() []string {\n\tkeys := make([]string, 0, len(r.enums))\n\tfor k := range r.enums {","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/internal/descriptor/registry.go#L472-L508","documentation":"ReserveGoPackageAlias registers a Go package alias used when generating imports. If the alias is already reserved for a DIFFERENT package path, the registry rejects it to avoid two distinct proto packages mapping to the same Go import name. Reserving the same alias for the same package path is idempotent and returns nil.","triggerScenarios":"Calling Registry.ReserveGoPackageAlias(alias, pkgpath) when r.pkgAliases[alias] exists and maps to a different pkgpath. Happens during loadFile/New when two proto files declare go_package paths that collapse to the same alias.","commonSituations":"Two .proto files in different directories share the same go_package basename (e.g. both use 'v1' as the final package element); vendored third-party protos whose go_package collides with local protos; monorepo merges introducing a second API version with an identical alias.","solutions":["Change the go_package option in one of the conflicting .proto files so each package path yields a unique alias","Import the conflicting proto with an explicit import_alias in the proto that references it","If generating with protoc-gen-openapiv2, adjust M flags to remap go_package paths uniquely","If the alias is intentionally the same package, ensure the pkgpath argument matches exactly (identical alias+path is allowed)"],"exampleFix":"// before\noption go_package = \"example.com/api/v1;v1\";   // in a.proto\noption go_package = \"example.com/other/v1;v1\";  // in b.proto -> alias 'v1' collision\n// after\noption go_package = \"example.com/api/v1;apiv1\";\noption go_package = \"example.com/other/v1;otherv1\";","handlingStrategy":"validation","validationCode":"if existing, ok := registryAliases[alias]; ok && existing != pkgpath {\n    return fmt.Errorf(\"alias %q already reserved for %q\", alias, pkgpath)\n}\n_ = registry.ReserveGoPackageAlias(alias, pkgpath)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt a go_package naming convention where the final ';alias' element is unique per proto package","Pre-warm a map of declared aliases from all .proto files before generation and detect collisions in CI","Use explicit import_alias when importing protos whose packages would collide"],"tags":["go","protobuf","codegen","naming-collision"],"backgroundTag":"package-alias-collision","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}