Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[Go] Conflicting proto file names (not path) cannot be used in Go ?

46 views
Skip to first unread message

Jan Pfeifer

unread,
Dec 4, 2024, 4:00:11 AM12/4/24
to Protocol Buffers
hi all,

Today I bumped into the conflicting file name registration runtime error below.

```
panic: proto: file "sentencepiece_model.proto" is already registered previously from: "github.com/eliben/go-sentencepiece/internal/model" currently from: "github.com/gomlx/go-huggingface/tokenizers/sentencepiece/private/protos" See https://protobuf.dev/reference/go/faq#namespace-conflict 
```

The two libraries I'm using define the protos under different proto `package` names, as well as different `option go_package` paths -- so in principle, I understand, the protos they define should be unrelated and have no conflict.

For the record, `syntax = "proto2"` is defined in both proto files.

Just the last part of the file name ("sentencepiece_model.proto") are the same, they are in different paths.

I own one of these libraries, so I could change the file name to something like:

"sentencepiece_model_<unique_hash>.proto"

And that works as expected -- but it is a sad solution :).

Am I misunderstanding the error ? Any suggestions on how to prevent such conflicts ? 

Many thanks in advance.

Em Rauch

unread,
Dec 4, 2024, 11:35:11 AM12/4/24
to Jan Pfeifer, Protocol Buffers
I believe the issue is more inherent to protobuf in general and not a Go specific thing; basically if you have a file that does `import "x.proto"` that needs to be able to be resolved uniquely. Note that it should not require the _file names_ themselves to be globally unique, the problem arises when you invoke protoc with something like this:

protoc -Iproject1 project1/foo.proto
protoc -Iproject2 project2/foo.proto

Which results in the two files being represented as their (necessarily globally unique name) of just "foo.proto". 

If you instead invoke proto without the -I, there would be no conflict (because the two files will have their canonical file names as "project1/foo.proto" and "project2/foo.proto"):

protoc project1/foo.proto
protoc project2/foo.proto

You may find more discussion about this (including some details which are Go specific) here: https://github.com/golang/protobuf/issues/1122


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/protobuf/9ab9719e-dda1-4809-ac61-89b41a4a9ae7n%40googlegroups.com.

Jan Pfeifer

unread,
Dec 4, 2024, 2:05:18 PM12/4/24
to Protocol Buffers
So this seems to be another one of those artifacts of Google's mono-repo (Bazel) view of the world -- where each file is used with the full path and uniquely identify it. 

Thanks for the link to the issue: this is a 4 years old issue, with dozen of followers.

For the record, and anyone ending in this thread: the long story (in the issue) short: there is no clean solution, and proto maintainers are not likely to solve it (my understanding from reading the issue in github)

I proposed a relatively simple work around by wrapping protoc with a script that uses the go import path (of the package in the current directory) as a unique key along the file name, which seems the correct result to achieve for a global unique name: see https://github.com/golang/protobuf/issues/1122#issuecomment-2518289653

Thanks Em, the pointers are very appreciated.
Jan
Reply all
Reply to author
Forward
0 new messages