Skip to content

Commit

Permalink
additional proto files are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimi committed Sep 9, 2022
1 parent 859470f commit 39637fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/caller/parseprotos.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package caller

import (
"errors"
"fmt"
"io"
"io/fs"
Expand All @@ -12,14 +13,16 @@ import (
clifs "github.com/vadimi/grpc-client-cli/internal/fs"
)

var errNoProtoFilesFound = errors.New("no proto files found")

func parseProtoFiles(protoDirs []string, protoImports []string) ([]*desc.FileDescriptor, error) {
protofiles, err := findProtoFiles(protoDirs)
if err != nil {
return nil, err
}

if len(protofiles) == 0 {
return nil, fmt.Errorf("no proto files found in %s", protoDirs)
return nil, fmt.Errorf("%w: %s", errNoProtoFilesFound, protoDirs)
}

importPaths := []string{}
Expand Down
4 changes: 4 additions & 0 deletions internal/caller/servicemetabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package caller

import (
"context"
"errors"
"fmt"

"github.com/jhump/protoreflect/desc"
Expand Down Expand Up @@ -37,6 +38,9 @@ func (s serviceMetaBase) GetAdditionalFiles(protoImports []string) ([]*desc.File
}
fileDesc, err := parseProtoFiles(protoImports, nil)
if err != nil {
if errors.Is(err, errNoProtoFilesFound) {
return nil, nil
}
return nil, fmt.Errorf("error parsing additional proto files: %w", err)
}
return fileDesc, nil
Expand Down

0 comments on commit 39637fd

Please sign in to comment.