fix: Handle duplicate registration of protocol-buffer files gracefully. (#10188)

This commit is contained in:
Sven Rebhan 2021-12-10 22:25:24 +01:00 committed by GitHub
parent 1b9572085b
commit aa642a4046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package xpath
import (
"errors"
"fmt"
"sort"
"strings"
@ -55,6 +56,13 @@ func (d *protobufDocument) Init() error {
if err != nil {
return fmt.Errorf("creating file descriptor from proto failed: %v", err)
}
if _, err := protoregistry.GlobalFiles.FindFileByPath(fileDesc.Path()); !errors.Is(err, protoregistry.NotFound) {
if err != nil {
return fmt.Errorf("searching for file %q in registry failed: %v", fileDesc.Path(), err)
}
d.Log.Warnf("Protocol buffer with path %q already registered. Skipping...", fileDesc.Path())
continue
}
if err := protoregistry.GlobalFiles.RegisterFile(fileDesc); err != nil {
return fmt.Errorf("registering file descriptor %q failed: %v", fileDesc.Package(), err)
}