@@ -2,11 +2,11 @@ package logdrains
22
33import (
44 "context"
5-
6- "gopkg.in/errgo.v1"
5+ "strings"
76
87 "github.com/Scalingo/cli/config"
98 "github.com/Scalingo/cli/io"
9+ "github.com/Scalingo/go-utils/errors/v2"
1010)
1111
1212type RemoveAddonOpts struct {
@@ -18,36 +18,41 @@ type RemoveAddonOpts struct {
1818func Remove (ctx context.Context , app string , opts RemoveAddonOpts ) error {
1919 c , err := config .ScalingoClient (ctx )
2020 if err != nil {
21- return errgo . Notef ( err , "fail to get Scalingo client to remove a log drain from the application " )
21+ return errors . Wrap ( ctx , err , "get Scalingo client" )
2222 }
2323
2424 if opts .AddonID != "" {
2525 // addon only
2626 err := c .LogDrainAddonRemove (ctx , app , opts .AddonID , opts .URL )
2727 if err != nil {
28- return errgo . Notef ( err , "fail to remove the log drain from the addon %s" , opts .AddonID )
28+ return errors . Wrap ( ctx , err , "remove log drain from addon " + opts .AddonID )
2929 }
3030 io .Status ("The log drain" , opts .URL , "has been deleted from the addon" , opts .AddonID )
3131 return nil
3232 }
3333
3434 err = c .LogDrainRemove (ctx , app , opts .URL )
3535 if err != nil {
36- io .Status ("fail to remove the log drain from the application:" , app , "\n \t " , err )
37- } else {
38- io .Status ("Log drain" , opts .URL , "has been deleted from the application" , app )
36+ return errors .Wrap (ctx , err , "remove log drain from application " + app )
3937 }
38+ io .Status ("Log drain" , opts .URL , "has been deleted from the application" , app )
4039
4140 if ! opts .OnlyApp {
4241 addons , err := c .AddonsList (ctx , app )
4342 if err != nil {
44- return errgo . Notef ( err , "fail to list addons to remove log drain" )
43+ return errors . Wrap ( ctx , err , "list addons to remove log drain" )
4544 }
4645
4746 for _ , addon := range addons {
4847 err := c .LogDrainAddonRemove (ctx , app , addon .ID , opts .URL )
4948 if err != nil {
50- io .Status ("fail to remove the log drain from the addon:" , addon .AddonProvider .Name , "\n \t " , err )
49+ // Check if this is a "not found" error, which can happen if the log drain
50+ // was already removed by the main API call
51+ if strings .Contains (err .Error (), "not found" ) {
52+ io .Status ("Log drain" , opts .URL , "was already removed from the addon" , addon .AddonProvider .Name )
53+ } else {
54+ io .Status ("Unable to remove the log drain from the addon:" , addon .AddonProvider .Name , "\n \t " , err )
55+ }
5156 } else {
5257 io .Status ("Log drain" , opts .URL , "has been deleted from the addon" , addon .AddonProvider .Name )
5358 }
0 commit comments