Skip to content

Commit

Permalink
refactor(alerts): replace errgo with ErrCtx
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneM committed Feb 16, 2024
1 parent 56a24f6 commit 4bc8428
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
7 changes: 3 additions & 4 deletions alerts/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package alerts
import (
"context"

"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/go-scalingo/v6"
"github.com/Scalingo/go-utils/errors/v2"
)

func Add(ctx context.Context, app string, params scalingo.AlertAddParams) error {
c, err := config.ScalingoClient(ctx)
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
return errors.Wrap(ctx, err, "get Scalingo client")
}

a, err := c.AlertAdd(ctx, app, params)
if err != nil {
return errgo.Mask(err)
return errors.Wrap(ctx, err, "add alert")
}

io.Status("Alert created for the container type", a.ContainerType)
Expand Down
9 changes: 5 additions & 4 deletions alerts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import (
"context"
"fmt"
"os"
"strconv"

"github.com/olekukonko/tablewriter"
"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/go-utils/errors/v2"
)

func List(ctx context.Context, app string) error {
c, err := config.ScalingoClient(ctx)
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
return errors.Wrap(ctx, err, "get Scalingo client")
}

alerts, err := c.AlertsList(ctx, app)
if err != nil {
return errgo.Mask(err)
return errors.Wrap(ctx, err, "list alerts")
}

t := tablewriter.NewWriter(os.Stdout)
Expand Down Expand Up @@ -49,7 +50,7 @@ func List(ctx context.Context, app string) error {

row := []string{
alert.ID,
fmt.Sprint(!alert.Disabled),
strconv.FormatBool(!alert.Disabled),
alert.ContainerType,
alert.Metric,
fmt.Sprintf("%s %.2f%s", above, alert.Limit, durationString),
Expand Down
7 changes: 3 additions & 4 deletions alerts/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package alerts
import (
"context"

"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/go-utils/errors/v2"
)

func Remove(ctx context.Context, app, id string) error {
c, err := config.ScalingoClient(ctx)
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
return errors.Wrapf(ctx, err, "get Scalingo client")
}

err = c.AlertRemove(ctx, app, id)
if err != nil {
return errgo.Mask(err)
return errors.Wrapf(ctx, err, "remove alert")
}

io.Status("The alert has been deleted")
Expand Down
7 changes: 3 additions & 4 deletions alerts/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package alerts
import (
"context"

"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/go-scalingo/v6"
"github.com/Scalingo/go-utils/errors/v2"
)

func Update(ctx context.Context, app, id string, params scalingo.AlertUpdateParams) error {
c, err := config.ScalingoClient(ctx)
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
return errors.Wrapf(ctx, err, "get Scalingo client")
}

_, err = c.AlertUpdate(ctx, app, id, params)
if err != nil {
return errgo.Mask(err, errgo.Any)
return errors.Wrapf(ctx, err, "update alert")
}

var msg string
Expand Down

0 comments on commit 4bc8428

Please sign in to comment.