Skip to content

Commit

Permalink
only ignore ambiguous id errors during clone
Browse files Browse the repository at this point in the history
  • Loading branch information
dschaller committed Sep 6, 2024
1 parent 1b32322 commit d4c31c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 17 additions & 5 deletions cmd/esc/cli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
)

type ambiguousIdentifierError struct {
legacyRef environmentRef
ref environmentRef
}

func (e ambiguousIdentifierError) Error() string {
return fmt.Sprintf(
"ambiguous path provided\n\nEnvironments found at both '%s' and '%s'.\nPlease specify the full path as <org-name>/<project-name>/<env-name>",
e.ref.String(),
e.legacyRef.String(),
)
}

type envCommand struct {
esc *escCommand

Expand Down Expand Up @@ -253,11 +266,10 @@ func (cmd *envCommand) getExistingEnvRefWithRelative(

// Require unambiguous path if both paths exist
if exists && existsLegacyPath {
return ref, fmt.Errorf(
"ambiguous path provided\n\nEnvironments found at both '%s' and '%s'.\nPlease specify the full path as <org-name>/<project-name>/<env-name>",
ref.String(),
legacyRef.String(),
)
return ref, ambiguousIdentifierError{
legacyRef: legacyRef,
ref: ref,
}
}

if existsLegacyPath {
Expand Down
7 changes: 6 additions & 1 deletion cmd/esc/cli/env_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ func newEnvCloneCmd(env *envCommand) *cobra.Command {
return err
}

ref, args, _ := env.getExistingEnvRef(ctx, args)
ref, args, err := env.getExistingEnvRef(ctx, args)
// An error will arise if an environment reference is ambiguous and can't be
// resolved to a single environment. The ref for the non-legacy environment will
// also be returned in this case.
// If the original ref is using a legacy ID of just env name return an error
// Otherwise we will ignore any conflict errors and assume the user meant <project-name>/<env-name>
var ambiguousIdErr ambiguousIdentifierError
if err != nil && !errors.As(err, &ambiguousIdErr) {
return err
}

if ref.isUsingLegacyID {
return errors.New("referring to an environment name ('env' or 'org/env') without a project is not supported")
}
Expand Down

0 comments on commit d4c31c1

Please sign in to comment.