Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions internal/librarian/java/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package java

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -30,6 +31,14 @@ const (
grcpProtoGroupID = "com.google.api.grpc"
)

var (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these do not need to be exported

// ErrInvalidDistributionName is returned when the distribution name format is invalid.
ErrInvalidDistributionName = errors.New("invalid distribution name")

// ErrAPIConfigNotFound is returned when the API config cannot be found.
ErrAPIConfigNotFound = errors.New("failed to find api config")
)

// grpcProtoPomData holds the data for rendering POM templates.
type grpcProtoPomData struct {
Proto coordinates
Expand Down Expand Up @@ -81,7 +90,7 @@ func collectModules(library *config.Library, libraryDir, googleapisDir string) (
distName := deriveDistributionName(library)
parts := strings.SplitN(distName, ":", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid distribution name %q: expected format groupID:artifactID", distName)
return nil, fmt.Errorf("%w %q: expected format groupID:artifactID", ErrInvalidDistributionName, distName)
}
gapicGroupID := parts[0]
gapicArtifactID := parts[1]
Expand All @@ -97,7 +106,7 @@ func collectModules(library *config.Library, libraryDir, googleapisDir string) (

apiCfg, err := serviceconfig.Find(googleapisDir, api.Path, config.LanguageJava)
if err != nil {
return nil, fmt.Errorf("failed to find api config for %s: %w", api.Path, err)
return nil, fmt.Errorf("%w for %s: %w", ErrAPIConfigNotFound, api.Path, err)
}
transport := apiCfg.Transport(config.LanguageJava)

Expand Down
11 changes: 9 additions & 2 deletions internal/librarian/java/pom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestCollectModules_Error(t *testing.T) {
for _, test := range []struct {
name string
library *config.Library
wantErr error
}{
{
name: "invalid distribution name",
Expand All @@ -94,6 +95,7 @@ func TestCollectModules_Error(t *testing.T) {
DistributionNameOverride: "invalid-name",
},
},
wantErr: ErrInvalidDistributionName,
},
{
name: "failed to find api config",
Expand All @@ -102,11 +104,16 @@ func TestCollectModules_Error(t *testing.T) {
{Path: "google/ads/unrecognized/v1"},
},
},
wantErr: ErrAPIConfigNotFound,
},
} {
t.Run(test.name, func(t *testing.T) {
if _, err := collectModules(test.library, t.TempDir(), "/nonexistent"); err == nil {
t.Error("collectModules() error = nil, want non-nil")
_, err := collectModules(test.library, t.TempDir(), "/nonexistent")
if err == nil {
t.Fatal("collectModules() error = nil, want non-nil")
}
if !errors.Is(err, test.wantErr) {
t.Errorf("collectModules() error = %v, want %v", err, test.wantErr)
}
})
}
Expand Down
Loading