From 39637fdc6349b1ce2eef87fe0f5da261a86c671f Mon Sep 17 00:00:00 2001 From: vadimi Date: Fri, 9 Sep 2022 09:56:04 -0400 Subject: [PATCH] additional proto files are optional --- internal/caller/parseprotos.go | 5 ++++- internal/caller/servicemetabase.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/caller/parseprotos.go b/internal/caller/parseprotos.go index 3f0bc6e..29655c9 100644 --- a/internal/caller/parseprotos.go +++ b/internal/caller/parseprotos.go @@ -1,6 +1,7 @@ package caller import ( + "errors" "fmt" "io" "io/fs" @@ -12,6 +13,8 @@ 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 { @@ -19,7 +22,7 @@ func parseProtoFiles(protoDirs []string, protoImports []string) ([]*desc.FileDes } 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{} diff --git a/internal/caller/servicemetabase.go b/internal/caller/servicemetabase.go index 36a1c8d..792cfae 100644 --- a/internal/caller/servicemetabase.go +++ b/internal/caller/servicemetabase.go @@ -2,6 +2,7 @@ package caller import ( "context" + "errors" "fmt" "github.com/jhump/protoreflect/desc" @@ -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