Fix error message for stack select failures
This commit is contained in:
parent
d419229301
commit
b3ee139b91
|
@ -44,4 +44,3 @@ script:
|
||||||
- make travis_${TRAVIS_EVENT_TYPE} TEST_FAST_TIMEOUT=10m
|
- make travis_${TRAVIS_EVENT_TYPE} TEST_FAST_TIMEOUT=10m
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://ufci1w66n3.execute-api.us-west-2.amazonaws.com/stage/travis
|
webhooks: https://ufci1w66n3.execute-api.us-west-2.amazonaws.com/stage/travis
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,14 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/pulumi/pulumi/pkg/backend/state"
|
"github.com/pulumi/pulumi/pkg/backend/state"
|
||||||
"github.com/pulumi/pulumi/pkg/tokens"
|
"github.com/pulumi/pulumi/pkg/tokens"
|
||||||
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
||||||
"github.com/pulumi/pulumi/pkg/util/contract"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// newStackSelectCmd handles both the "local" and "cloud" scenarios in its implementation.
|
// newStackSelectCmd handles both the "local" and "cloud" scenarios in its implementation.
|
||||||
|
@ -40,15 +39,15 @@ func newStackSelectCmd() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask all known backends about this stack.
|
// Ask all known backends about this stack.
|
||||||
|
var result error
|
||||||
bes, hasClouds := allBackends()
|
bes, hasClouds := allBackends()
|
||||||
toSelect := tokens.QName(args[0])
|
toSelect := tokens.QName(args[0])
|
||||||
for _, b := range bes {
|
for _, b := range bes {
|
||||||
stack, err := b.GetStack(toSelect)
|
stack, err := b.GetStack(toSelect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If there is an error, file it away, but keep going in case it's a transient cloud error.
|
// If there is an error, file it away, but keep going in case it's a transient cloud error.
|
||||||
_, fmterr := fmt.Fprintf(os.Stderr,
|
result = multierror.Append(result, errors.Wrapf(err,
|
||||||
"error: could not query '%s' backend for possible stack select", b.Name())
|
"could not query '%s' backend for stack selection", b.Name()))
|
||||||
contract.IgnoreError(fmterr)
|
|
||||||
continue
|
continue
|
||||||
} else if stack != nil {
|
} else if stack != nil {
|
||||||
return state.SetCurrentStack(toSelect)
|
return state.SetCurrentStack(toSelect)
|
||||||
|
@ -59,10 +58,9 @@ func newStackSelectCmd() *cobra.Command {
|
||||||
// message if no clouds are logged into, since that is presumably a common mistake.
|
// message if no clouds are logged into, since that is presumably a common mistake.
|
||||||
msg := fmt.Sprintf("no stack named '%s' found", toSelect)
|
msg := fmt.Sprintf("no stack named '%s' found", toSelect)
|
||||||
if !hasClouds {
|
if !hasClouds {
|
||||||
return errors.New(msg +
|
msg += "; you aren't logged into the Pulumi Cloud -- did you forget to 'pulumi login'?"
|
||||||
"; you aren't logged into the Pulumi Cloud -- did you forget to 'pulumi login'?")
|
|
||||||
}
|
}
|
||||||
return errors.New(msg)
|
return multierror.Append(result, errors.New(msg))
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
cmd.PersistentFlags().StringVarP(
|
cmd.PersistentFlags().StringVarP(
|
||||||
|
|
|
@ -91,11 +91,9 @@ func errorMessage(err error) string {
|
||||||
}
|
}
|
||||||
msg := fmt.Sprintf("%d errors occurred:", len(wr))
|
msg := fmt.Sprintf("%d errors occurred:", len(wr))
|
||||||
for i, werr := range wr {
|
for i, werr := range wr {
|
||||||
if i != len(wr)-1 {
|
msg += fmt.Sprintf("\n\t%d) %s", i, errorMessage(werr))
|
||||||
msg += "\n"
|
|
||||||
}
|
|
||||||
msg += fmt.Sprintf("\t- %s", errorMessage(werr))
|
|
||||||
}
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue