Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CLI): not found errors #2114

Merged
merged 6 commits into from
Jan 31, 2025
Merged
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
6 changes: 3 additions & 3 deletions cmd/conduit/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package api

import (
"context"
"fmt"

"github.com/conduitio/conduit/pkg/foundation/cerrors"
apiv1 "github.com/conduitio/conduit/proto/api/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -38,7 +38,7 @@ func NewClient(ctx context.Context, address string) (*Client, error) {
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, fmt.Errorf("failed to create gRPC client: %w", err)
return nil, cerrors.Errorf("failed to create gRPC client: %w", err)
}

client := &Client{
Expand All @@ -60,7 +60,7 @@ func NewClient(ctx context.Context, address string) (*Client, error) {
func (c *Client) CheckHealth(ctx context.Context, address string) error {
healthResp, err := c.HealthClient.Check(ctx, &healthgrpc.HealthCheckRequest{})
if err != nil || healthResp.Status != healthgrpc.HealthCheckResponse_SERVING {
return fmt.Errorf("we couldn't connect to Conduit at the configured address %q\n"+
return cerrors.Errorf("we couldn't connect to Conduit at the configured address %q\n"+
"Please execute `conduit run` to start it.\nTo check the current configured `api.grpc.address`, run `conduit config`\n\n"+
"Error details: %v", address, err)
}
Expand Down
10 changes: 4 additions & 6 deletions cmd/conduit/cecdysis/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ package cecdysis

import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/conduitio/conduit/cmd/conduit/api"
"github.com/conduitio/conduit/pkg/conduit"
"github.com/conduitio/conduit/pkg/foundation/cerrors"
"github.com/conduitio/ecdysis"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -57,14 +56,12 @@ func (CommandWithExecuteWithClientDecorator) Decorate(_ *ecdysis.Ecdysis, cmd *c

grpcAddress, err := getGRPCAddress(cmd)
if err != nil {
return fmt.Errorf("error reading gRPC address: %w", err)
return cerrors.Errorf("error reading gRPC address: %w", err)
}

client, err := api.NewClient(cmd.Context(), grpcAddress)
if err != nil {
// Not an error we need to escalate to the main CLI execution. We'll print it out and not execute further.
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
return nil
return err
}
defer client.Close()

Expand All @@ -75,6 +72,7 @@ func (CommandWithExecuteWithClientDecorator) Decorate(_ *ecdysis.Ecdysis, cmd *c
return nil
}

// getGRPCAddress returns the gRPC address configured by the user. If no address is found, the default address is returned.
func getGRPCAddress(cmd *cobra.Command) (string, error) {
var (
path string
Expand Down
7 changes: 5 additions & 2 deletions cmd/conduit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"fmt"
"os"

"github.com/conduitio/conduit/cmd/conduit/cecdysis"
Expand All @@ -29,8 +28,12 @@ func main() {
cmd := e.MustBuildCobraCommand(&root.RootCommand{})
cmd.CompletionOptions.DisableDefaultCmd = true

// Don't want to show usage when there's some unexpected error executing the command
// Help will still be shown via --help
cmd.SilenceUsage = true

if err := cmd.Execute(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
// error is already printed out
os.Exit(1)
}
os.Exit(0)
Expand Down
2 changes: 1 addition & 1 deletion cmd/conduit/root/connectorplugins/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Name: c.args.connectorPluginID,
})
if err != nil {
return fmt.Errorf("failed to list connector plguin: %w", err)
return cerrors.Errorf("failed to list connector plguin: %w", err)
}

if len(resp.Plugins) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/conduit/root/connectorplugins/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/alexeyco/simpletable"
"github.com/conduitio/conduit/cmd/conduit/api"
"github.com/conduitio/conduit/cmd/conduit/cecdysis"
"github.com/conduitio/conduit/pkg/foundation/cerrors"
apiv1 "github.com/conduitio/conduit/proto/api/v1"
"github.com/conduitio/ecdysis"
)
Expand Down Expand Up @@ -70,7 +71,7 @@ func (c *ListCommand) ExecuteWithClient(ctx context.Context, client *api.Client)
Name: regex,
})
if err != nil {
return fmt.Errorf("failed to list connector plugins: %w", err)
return cerrors.Errorf("failed to list connector plugins: %w", err)
}

sort.Slice(resp.Plugins, func(i, j int) bool {
Expand Down
4 changes: 2 additions & 2 deletions cmd/conduit/root/connectors/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: c.args.ConnectorID,
})
if err != nil {
return fmt.Errorf("failed to get connector: %w", err)
return cerrors.Errorf("failed to get connector: %w", err)
}

var processors []*apiv1.Processor
Expand All @@ -90,7 +90,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: processorID,
})
if err != nil {
return fmt.Errorf("failed to get processor: %w", err)
return cerrors.Errorf("failed to get processor: %w", err)
}
processors = append(processors, processor.Processor)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/conduit/root/connectors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ package connectors

import (
"context"
"fmt"
"sort"

"github.com/alexeyco/simpletable"
"github.com/conduitio/conduit/cmd/conduit/api"
"github.com/conduitio/conduit/cmd/conduit/cecdysis"
"github.com/conduitio/conduit/cmd/conduit/internal/display"
"github.com/conduitio/conduit/pkg/foundation/cerrors"
apiv1 "github.com/conduitio/conduit/proto/api/v1"
"github.com/conduitio/ecdysis"
)
Expand Down Expand Up @@ -70,7 +70,7 @@ func (c *ListCommand) ExecuteWithClient(ctx context.Context, client *api.Client)
PipelineId: c.flags.PipelineID,
})
if err != nil {
return fmt.Errorf("failed to list connectors: %w", err)
return cerrors.Errorf("failed to list connectors: %w", err)
}

sort.Slice(resp.Connectors, func(i, j int) bool {
Expand Down
4 changes: 2 additions & 2 deletions cmd/conduit/root/initialize/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *InitCommand) createDirs() error {
fmt.Printf("Directory '%s' already exists, skipping...\n", path)
continue
}
return fmt.Errorf("failed to create directory '%s': %w", path, err)
return cerrors.Errorf("failed to create directory '%s': %w", path, err)
}

fmt.Printf("Created directory: %s\n", path)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (c *InitCommand) Execute(_ context.Context) error {

err = c.createConfigYAML()
if err != nil {
return fmt.Errorf("failed to create config YAML: %w", err)
return cerrors.Errorf("failed to create config YAML: %w", err)
}

fmt.Println(`
Expand Down
14 changes: 7 additions & 7 deletions cmd/conduit/root/pipelines/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: c.args.PipelineID,
})
if err != nil {
return fmt.Errorf("failed to get pipeline: %w", err)
return cerrors.Errorf("failed to get pipeline: %w", err)
}

// Fetch pipeline processors
Expand All @@ -91,7 +91,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: processorID,
})
if err != nil {
return fmt.Errorf("failed to get processor: %w", err)
return cerrors.Errorf("failed to get processor: %w", err)
}
pipelineProcessors = append(pipelineProcessors, processor.Processor)
}
Expand All @@ -101,7 +101,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
PipelineId: c.args.PipelineID,
})
if err != nil {
return fmt.Errorf("failed to list connectors for pipeline %s: %w", c.args.PipelineID, err)
return cerrors.Errorf("failed to list connectors for pipeline %s: %w", c.args.PipelineID, err)
}

connectors := make([]*apiv1.Connector, 0, len(connectorsResp.Connectors))
Expand All @@ -111,7 +111,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: conn.Id,
})
if err != nil {
return fmt.Errorf("failed to get connector: %w", err)
return cerrors.Errorf("failed to get connector: %w", err)
}

connectors = append(connectors, connDetails.Connector)
Expand All @@ -128,7 +128,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: processorID,
})
if err != nil {
return fmt.Errorf("failed to get processor: %w", err)
return cerrors.Errorf("failed to get processor: %w", err)
}
processors = append(processors, processor.Processor)
}
Expand All @@ -139,12 +139,12 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: c.args.PipelineID,
})
if err != nil {
return fmt.Errorf("failed to fetch DLQ for pipeline %s: %w", c.args.PipelineID, err)
return cerrors.Errorf("failed to fetch DLQ for pipeline %s: %w", c.args.PipelineID, err)
}

err = displayPipeline(c.output, pipelineResp.Pipeline, pipelineProcessors, connectors, connectorProcessors, dlq.Dlq)
if err != nil {
return fmt.Errorf("failed to display pipeline %s: %w", c.args.PipelineID, err)
return cerrors.Errorf("failed to display pipeline %s: %w", c.args.PipelineID, err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/conduit/root/pipelines/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package pipelines

import (
"context"
"fmt"
"sort"

"github.com/conduitio/conduit/cmd/conduit/internal/display"
"github.com/conduitio/conduit/pkg/foundation/cerrors"

"github.com/alexeyco/simpletable"
"github.com/conduitio/conduit/cmd/conduit/api"
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *ListCommand) Usage() string { return "list" }
func (c *ListCommand) ExecuteWithClient(ctx context.Context, client *api.Client) error {
resp, err := client.PipelineServiceClient.ListPipelines(ctx, &apiv1.ListPipelinesRequest{})
if err != nil {
return fmt.Errorf("failed to list pipelines: %w", err)
return cerrors.Errorf("failed to list pipelines: %w", err)
}

sort.Slice(resp.Pipelines, func(i, j int) bool {
Expand Down
2 changes: 1 addition & 1 deletion cmd/conduit/root/processorplugins/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Name: c.args.processorPluginID,
})
if err != nil {
return fmt.Errorf("failed to get processor plugin: %w", err)
return cerrors.Errorf("failed to get processor plugin: %w", err)
}

if len(resp.Plugins) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/conduit/root/processorplugins/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/alexeyco/simpletable"
"github.com/conduitio/conduit/cmd/conduit/api"
"github.com/conduitio/conduit/cmd/conduit/cecdysis"
"github.com/conduitio/conduit/pkg/foundation/cerrors"
apiv1 "github.com/conduitio/conduit/proto/api/v1"
"github.com/conduitio/ecdysis"
)
Expand Down Expand Up @@ -70,7 +71,7 @@ func (c *ListCommand) ExecuteWithClient(ctx context.Context, client *api.Client)
Name: regex,
})
if err != nil {
return fmt.Errorf("failed to list processor plugins: %w", err)
return cerrors.Errorf("failed to list processor plugins: %w", err)
}

sort.Slice(resp.Plugins, func(i, j int) bool {
Expand Down
2 changes: 1 addition & 1 deletion cmd/conduit/root/processors/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Cli
Id: c.args.ProcessorID,
})
if err != nil {
return fmt.Errorf("failed to get processor: %w", err)
return cerrors.Errorf("failed to get processor: %w", err)
}

displayProcessor(c.output, resp.Processor)
Expand Down
3 changes: 2 additions & 1 deletion cmd/conduit/root/processors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sort"

"github.com/conduitio/conduit/cmd/conduit/internal/display"
"github.com/conduitio/conduit/pkg/foundation/cerrors"

"github.com/alexeyco/simpletable"
"github.com/conduitio/conduit/cmd/conduit/api"
Expand Down Expand Up @@ -59,7 +60,7 @@ func (c *ListCommand) Usage() string { return "list" }
func (c *ListCommand) ExecuteWithClient(ctx context.Context, client *api.Client) error {
resp, err := client.ProcessorServiceClient.ListProcessors(ctx, &apiv1.ListProcessorsRequest{})
if err != nil {
return fmt.Errorf("failed to list processors: %w", err)
return cerrors.Errorf("failed to list processors: %w", err)
}

sort.Slice(resp.Processors, func(i, j int) bool {
Expand Down