Documentation
¶
Overview ¶
Package collide detects Protobuf namespace collisions between modules.
The failure this prevents ¶
Two Go modules that each vendor a copy of the same `.proto` produce two generated packages that both register the same file path and the same fully-qualified names into the process-global registry from `init()`. Any binary linking both crashes before `main` runs.
Nothing catches this today. Per-module linting operates within a module, so each repository is individually clean; the collision exists only in the link graph, which no Protobuf tool looks at. The escape hatch is worse than the crash — under `GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn` the second registration is dropped, so a loud startup crash becomes a silent wrong answer.
What is checked ¶
Check mirrors what `protoregistry.RegisterFile` rejects, because that is the function that panics:
- the file's import path;
- each of the file's top-level declarations — messages, enums, extensions and services — by fully-qualified name;
- the values of each top-level enum. `rangeTopLevelDescriptors` enumerates them alongside the enum itself, because an enum value is scoped to the enum's parent rather than to the enum: two modules in one Protobuf package whose enums both spell a value `UNSPECIFIED` conflict over that name even though the enums are differently named;
- the file's Protobuf package and every ancestor of it, against the other modules' declarations. A package entry and a descriptor cannot share a name, which `RegisterFile` reports as a "package name conflict". Two packages sharing a name is not a conflict, and is not reported.
Nested declarations are not compared separately. A nested name can only collide if the top-level name enclosing it already does, and `RegisterFile` itself checks only top-level descriptors.
A name claimed twice by a single module is reported too. Nothing else catches it: the module's own build does not, because protocompile links each file separately and two files in one module may declare the same fully-qualified name without error, and `RegisterFile` then panics on the second one just as it would across modules.
This is detection. Nothing here changes how generated code registers itself, or how `protoregistry` behaves.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Claim ¶
type Claim struct {
// Module is the claiming module's Name.
Module string
// File is the import path of the .proto that declares it.
File string
}
Claim records one module's claim on a name.
type Collision ¶
type Collision struct {
Kind Kind
// Name is the import path (KindFile) or fully-qualified name
// (KindSymbol) that was claimed twice.
Name string
// Claims is every claim on Name, ordered by module then file.
Claims []Claim
}
Collision is one name claimed by more than one module.
func Check ¶
Check compiles each module independently and reports every import path and fully-qualified name claimed more than once — by two modules, or by two files of one module, both of which panic in `protoregistry.RegisterFile`.
A module that cannot be read or compiled, or that holds no `.proto` at all, is an error rather than a collision: it has not been cleared, and reporting it as clean would be the same silent pass this package exists to remove.
The returned collisions are ordered deterministically, so output can be compared across runs.
type Module ¶
type Module struct {
// Name identifies the module in reports. It is the operator's label —
// a Go module path or a repository name — and is never interpreted.
Name string
// Root is the import root. Import paths inside this module resolve
// relative to it, so a file at <Root>/pxf/annotations.proto is
// imported as "pxf/annotations.proto".
Root string
// Paths optionally limits which files are checked, relative to Root.
// When empty every .proto beneath Root is checked.
Paths []string
}
Module is one unit whose namespace claims are compared against the others.