Skip to content

Commit

Permalink
catch provider errors and improve overall error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Mar 14, 2024
1 parent 786ca75 commit 234b1a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.0
require (
github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/jonhadfield/githosts-utils v0.0.0-20240313174126-39bd42e7a7eb
github.com/jonhadfield/githosts-utils v0.0.0-20240314223950-e790099ddc0f
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
gitlab.com/tozd/go/errors v0.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxC
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/jonhadfield/githosts-utils v0.0.0-20240313174126-39bd42e7a7eb h1:9/ds51JG/66mSCsHrE3V9GkG9uAeOb4PNRyJhcb3cuM=
github.com/jonhadfield/githosts-utils v0.0.0-20240313174126-39bd42e7a7eb/go.mod h1:Iw/QevnMRfpwyAL8vQPqNOEh2FJjoKMh64uuxyN3o+Q=
github.com/jonhadfield/githosts-utils v0.0.0-20240314223950-e790099ddc0f h1:5GhvocV4MBzKU7FL7I2RttpnCLqHeQdtHCgK/Nfg0Rc=
github.com/jonhadfield/githosts-utils v0.0.0-20240314223950-e790099ddc0f/go.mod h1:Iw/QevnMRfpwyAL8vQPqNOEh2FJjoKMh64uuxyN3o+Q=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,12 @@ func execProviderBackups() {

succeeded, failed := getBackupsStats(backupResults)

if failed > 0 {
switch {
case succeeded == 0 && failed >= 0:
logger.Println("all backups failed")
case succeeded > 0 && failed > 0:
logger.Println("backups completed with errors")
} else {
default:
logger.Println("backups complete")
}

Expand All @@ -508,6 +511,11 @@ func execProviderBackups() {

logger.Printf("next run scheduled for: %s", nextBackupTime.Format("2006-01-02 15:04:05 -0700 MST"))
}

if failed > 0 {
os.Exit(1)
}

}

func getProjectMinimumAccessLevel() int {
Expand Down
8 changes: 8 additions & 0 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ func getBackupsStats(br BackupResults) (ok, failed int) {
}

for _, pr := range *br.Results {
// catch error from provider
if pr.Results.Error != nil {
failed++

continue
}

for _, r := range pr.Results.BackupResults {
// catch error from repository backup
if r.Error != nil {
failed++

Expand Down

0 comments on commit 234b1a4

Please sign in to comment.