Giter VIP home page Giter VIP logo

Comments (6)

jhump avatar jhump commented on July 27, 2024 1

@Adol1111, thanks for reporting this and providing such a great repro case!

This was in fact supposed to be fixed in v1.15.1 (here). But I see the problem: in that patch, we only try to replace dynamic extensions in the files that are directly compiled, not their imports. So with your repro case, it only tries to replace the dynamic extensions in a.proto, but the problematic extensions are in the imported b.proto file. I think the fix will be fairly straight-forward.

from protoreflect.

jhump avatar jhump commented on July 27, 2024

FYI, a work-around until a release with a fix is created is to have your code provide all file names to the call to ParseFiles, including any indirectly imported files.

So in your repro case, the following diff causes it to work as expected because we supply both a.proto and b.proto to the parser:

diff --git a/main.go b/main.go
index fc7d6de..3aa6765 100644
--- a/main.go
+++ b/main.go
@@ -15,7 +15,7 @@ import (
 )
 
 func main() {
-       pb, err := loadProto("a.proto", "./example", "./third_parts")
+       pb, err := loadProto()
        if err != nil {
                fmt.Println(err)
        }
@@ -40,12 +40,12 @@ func main() {
        fmt.Println("ok")
 }
 
-func loadProto(entryFile string, dirs ...string) (*desc.FileDescriptor, error) {
+func loadProto() (*desc.FileDescriptor, error) {
        parser := protoparse.Parser{
                IncludeSourceCodeInfo: true,
-               ImportPaths:           dirs,
+               ImportPaths:           []string{"./example", "./third_parts"},
        }
-       ds, err := parser.ParseFiles(entryFile)
+       ds, err := parser.ParseFiles("a.proto", "b.proto")
        if err != nil {
                return nil, err
        }

from protoreflect.

Adol1111 avatar Adol1111 commented on July 27, 2024

Thanks, but it's still quite troublesome. I will use the old version first for now, and wait for your patch.

from protoreflect.

jhump avatar jhump commented on July 27, 2024

A patch is available in 4f8401b.

I am still in the process of trying to introduce a v2 of this repo, and am hoping that there will only need to be one more (final) v1 release. So I've put this patch on the v1 branch instead of on the default branch. (Hopefully soon, the default branch will become what's on the v2 branch.)

You could use this patch if you want via go get github.com/jhump/protoreflect@4f8401b.

from protoreflect.

jhump avatar jhump commented on July 27, 2024

I ended up putting the patch commit on master and making another v1 release (v1.15.2). This is fixed in that newer release.

from protoreflect.

Adol1111 avatar Adol1111 commented on July 27, 2024

I'm very sorry for the late feedback. I updated the version last week. It seems to be fixed already. Thank you very much.

from protoreflect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.