Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
0michalsokolowski0 committed Sep 9, 2024
1 parent e4b3d6e commit def7656
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions internal/cmd/stack/stack_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ func getStackID(cliCtx *cli.Context) (string, error) {
func getStack(cliCtx *cli.Context) (*stack, error) {
if cliCtx.IsSet(flagStackID.Name) {
stackID := cliCtx.String(flagStackID.Name)
stack, found, err := stackGetByID(cliCtx.Context, stackID)
stack, err := stackGetByID(cliCtx.Context, stackID)
if err != nil {
return nil, fmt.Errorf("failed to check if stack exists: %w", err)
}
if errors.Is(err, errNoStackFound) {
return nil, fmt.Errorf("stack with id %q could not be found. Please check that the stack exists and that you have access to it. To list available stacks run: spacectl stack list", stackID)
}

if !found {
return nil, fmt.Errorf("stack with id %q could not be found. Please check that the stack exists and that you have access to it. To list available stacks run: spacectl stack list", stackID)
return nil, fmt.Errorf("failed to check if stack exists: %w", err)
}

return stack, nil
} else if cliCtx.IsSet(flagRun.Name) {
runID := cliCtx.String(flagRun.Name)
stack, found, err := stackGetByRunID(cliCtx.Context, runID)
if err != nil {
fmt.Printf("Failed to get stack by run id: %v\n", err)
} else {
if !found {
return nil, fmt.Errorf("run with id %q was not found. Please check that the run exists and that you have access to it. To list available stacks run: spacectl stack run list", runID)
}
return nil, fmt.Errorf("failed to get stack by run id: %w", err)
}

return stack, nil
if !found {
return nil, fmt.Errorf("run with id %q was not found. Please check that the run exists and that you have access to it. To list available stacks run: spacectl stack run list", runID)
}

return stack, nil
}

subdir, err := getGitRepositorySubdir()
Expand Down Expand Up @@ -84,7 +84,7 @@ func getStack(cliCtx *cli.Context) (*stack, error) {
return got, nil
}

func stackGetByID(ctx context.Context, stackID string) (*stack, bool, error) {
func stackGetByID(ctx context.Context, stackID string) (*stack, error) {
var query struct {
Stack struct {
stack
Expand All @@ -97,14 +97,14 @@ func stackGetByID(ctx context.Context, stackID string) (*stack, bool, error) {

err := authenticated.Client.Query(ctx, &query, variables)
if err != nil {
return nil, false, fmt.Errorf("failed to query GraphQL API when checking if a stack exists: %w", err)
return nil, fmt.Errorf("failed to query GraphQL API when checking if a stack exists: %w", err)
}

if query.Stack.ID != stackID {
return nil, false, nil
return nil, errNoStackFound
}

return &query.Stack.stack, true, nil
return &query.Stack.stack, nil
}

func stackGetByRunID(ctx context.Context, runID string) (*stack, bool, error) {
Expand Down

0 comments on commit def7656

Please sign in to comment.