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

Add informative error #602

Merged
merged 6 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### To be Released

* Add informative error in case of container type error
curzolapierre marked this conversation as resolved.
Show resolved Hide resolved
[602](https://github.com/Scalingo/cli/pull/602)

### 1.19.3

* Add support for new log drain/addon log drain events
Expand Down
44 changes: 43 additions & 1 deletion apps/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"strings"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/go-scalingo/debug"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/cli/utils"
"github.com/Scalingo/go-scalingo"
"github.com/Scalingo/go-scalingo/debug"
"github.com/Scalingo/go-scalingo/http"
"github.com/Scalingo/go-utils/errors"
"gopkg.in/errgo.v1"
)

Expand Down Expand Up @@ -107,6 +109,11 @@ func Scale(app string, sync bool, types []string) error {
res, err := c.AppsScale(app, scaleParams)
if err != nil {
if !utils.IsPaymentRequiredAndFreeTrialExceededError(err) {
reqestFailedError, ok := errors.ErrgoRoot(err).(*http.RequestFailedError)
if !ok || reqestFailedError.Code == 422 {
curzolapierre marked this conversation as resolved.
Show resolved Hide resolved
return formatContainerTypesError(c, app)
}

return errgo.Mask(err)
}
// If error is Payment Required and user tries to exceed its free trial
Expand Down Expand Up @@ -140,6 +147,41 @@ func Scale(app string, sync bool, types []string) error {
return nil
}

func formatContainerTypesError(c *scalingo.Client, app string) error {
containerTypes, _ := c.AppsPs(app)
curzolapierre marked this conversation as resolved.
Show resolved Hide resolved
var containerTypesName string

if len(containerTypes) == 0 {
return errgo.New("You haven't container types yet.\nPlease refer to the documentation to deploy your application.")
curzolapierre marked this conversation as resolved.
Show resolved Hide resolved
}

for _, containerType := range containerTypes {
if containerTypesName == "" {
containerTypesName = "'" + containerType.Name + "'"
continue
}
containerTypesName = containerTypesName + ", '" + containerType.Name + "'"
}

errMessage := `Containers type not found.

Your available container `
if len(containerTypes) > 1 {
errMessage += "types are"
} else {
errMessage += "type is"
}
errMessage += ": " + containerTypesName + `.

Example of usage:
scalingo --app my-app scale web:2 worker:1
scalingo --app my-app scale web:1:XL
scalingo --app my-app scale web:+1 worker:-1

Use 'scalingo scale --help' for more information`
return errgo.New(errMessage)
}

func autoscaleDisableMessage(typesWithAutoscaler []string) string {
if len(typesWithAutoscaler) <= 0 {
return ""
Expand Down