Skip to content

Commit ba0ed40

Browse files
authored
CLOUDP-273727 "atlas deployments search index describe" fails with unclear error message when local deployment is paused (#3284)
1 parent 4605aaa commit ba0ed40

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

internal/cli/deployments/options/deployment_opts_pre_run.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package options
1717
import (
1818
"context"
1919
"errors"
20+
"fmt"
2021
"runtime"
2122
"slices"
2223

@@ -26,6 +27,8 @@ import (
2627
atlasv2 "go.mongodb.org/atlas-sdk/v20240805001/admin"
2728
)
2829

30+
var errDeploymentUnexpectedState = errors.New("deployment is in unexpected state")
31+
2932
func (opts *DeploymentOpts) listDeployments(ctx context.Context, projectID string) ([]Deployment, error) {
3033
var atlasDeployments, localDeployments []Deployment
3134
var atlasErr, localErr error
@@ -72,9 +75,20 @@ func (opts *DeploymentOpts) SelectDeployments(ctx context.Context, projectID str
7275
}
7376

7477
deployments = opts.filterDeploymentByName(deployments...)
75-
deployments = opts.filterDeploymentByState(deployments, states...)
78+
if opts.DeploymentName == "" {
79+
deployments = opts.filterDeploymentByState(deployments, states...)
80+
}
81+
82+
d, err := opts.Select(deployments)
83+
if err != nil {
84+
return Deployment{}, err
85+
}
86+
87+
if len(states) > 0 && !slices.Contains(states, d.StateName) {
88+
return Deployment{}, fmt.Errorf("%w: %s", errDeploymentUnexpectedState, d.StateName)
89+
}
7690

77-
return opts.Select(deployments)
91+
return d, nil
7892
}
7993

8094
func isUnauthenticatedErr(err error) bool {

internal/cli/deployments/search/indexes/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type ListOpts struct {
4343
}
4444

4545
func (opts *ListOpts) Run(ctx context.Context) error {
46-
if _, err := opts.SelectDeployments(ctx, opts.ConfigProjectID()); err != nil {
46+
if _, err := opts.SelectDeployments(ctx, opts.ConfigProjectID(), options.IdleState); err != nil {
4747
return err
4848
}
4949

0 commit comments

Comments
 (0)