Skip to content

Commit

Permalink
fix: wrap error messages with errtrace.Wrap() in relevant files
Browse files Browse the repository at this point in the history
- Add `braces.dev/errtrace` as a required module in `go.mod`
- Wrap `plugin.Exec()` with `errtrace.Wrap()` in `main.go`
- Wrap error messages with `errtrace.Wrap()` in `plugin.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Dec 6, 2023
1 parent 1f0fc09 commit f333a19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/appleboy/drone-lambda
go 1.19

require (
braces.dev/errtrace v0.2.0
github.com/aws/aws-sdk-go v1.48.13
github.com/gookit/goutil v0.6.14
github.com/joho/godotenv v1.5.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
braces.dev/errtrace v0.2.0 h1:1/XzHNUJ4ZVLhu3FzoQ5eJMa4wlj9LKKm/ABAVx2mbQ=
braces.dev/errtrace v0.2.0/go.mod h1:YQpXdo+u5iimgQdZzFoic8AjedEDncXGpp6/2SfazzI=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"time"

"braces.dev/errtrace"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -232,5 +233,5 @@ func run(c *cli.Context) error {
},
}

return plugin.Exec()
return errtrace.Wrap(plugin.Exec())
}
23 changes: 12 additions & 11 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

"braces.dev/errtrace"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
Expand Down Expand Up @@ -86,7 +87,7 @@ func (p Plugin) Exec() error {
p.dump(p.Config)

if p.Config.FunctionName == "" {
return errors.New("missing lambda function name")
return errtrace.Wrap(errors.New("missing lambda function name"))
}

sources := trimValues(p.Config.Source)
Expand All @@ -95,7 +96,7 @@ func (p Plugin) Exec() error {
len(sources) == 0 &&
p.Config.ZipFile == "" &&
p.Config.ImageURI == "" {
return errors.New("missing zip source or s3 bucket/key or image uri")
return errtrace.Wrap(errors.New("missing zip source or s3 bucket/key or image uri"))
}

// Create Lambda service client
Expand Down Expand Up @@ -149,7 +150,7 @@ func (p Plugin) Exec() error {
zip := archiver.NewZip()
if len(files) != 0 {
if err := zip.Archive(files, path); err != nil {
return err
return errtrace.Wrap(err)
}

p.Config.ZipFile = path
Expand All @@ -159,7 +160,7 @@ func (p Plugin) Exec() error {
if p.Config.ZipFile != "" {
contents, err := os.ReadFile(p.Config.ZipFile)
if err != nil {
return err
return errtrace.Wrap(err)
}

input.SetZipFile(contents)
Expand Down Expand Up @@ -230,7 +231,7 @@ func (p Plugin) Exec() error {
// UpdateFunctionConfiguration API operation for AWS Lambda.
log.Println("Update function configuration ...")
if err := p.checkStatus(svc); err != nil {
return err
return errtrace.Wrap(err)
}
lambdaConfig, err := svc.UpdateFunctionConfiguration(cfg)
if err != nil {
Expand All @@ -256,15 +257,15 @@ func (p Plugin) Exec() error {
// Message from an error.
log.Println(err.Error())
}
return err
return errtrace.Wrap(err)
}

p.dump(lambdaConfig)
}

log.Println("Update function code ...")
if err := p.checkStatus(svc); err != nil {
return err
return errtrace.Wrap(err)
}
lambdaConfig, err := svc.UpdateFunctionCode(input)
if err != nil {
Expand Down Expand Up @@ -292,7 +293,7 @@ func (p Plugin) Exec() error {
// Message from an error.
log.Println(err.Error())
}
return err
return errtrace.Wrap(err)
}

p.dump(lambdaConfig)
Expand All @@ -307,7 +308,7 @@ func (p *Plugin) checkStatus(svc *lambda.Lambda) error {
FunctionName: aws.String(p.Config.FunctionName),
})
if err != nil {
return err
return errtrace.Wrap(err)
}
log.Println("Current State:", aws.StringValue(lambdaConfig.State))
if aws.StringValue(lambdaConfig.State) != lambda.StateActive {
Expand All @@ -322,7 +323,7 @@ func (p *Plugin) checkStatus(svc *lambda.Lambda) error {
request.WithWaiterMaxAttempts(p.Config.MaxAttempts),
); err != nil {
log.Println(err.Error())
return err
return errtrace.Wrap(err)
}
}

Expand All @@ -339,7 +340,7 @@ func (p *Plugin) checkStatus(svc *lambda.Lambda) error {
request.WithWaiterMaxAttempts(p.Config.MaxAttempts),
); err != nil {
log.Println(err.Error())
return err
return errtrace.Wrap(err)
}
}

Expand Down

0 comments on commit f333a19

Please sign in to comment.