@@ -3,6 +3,8 @@ package ecs
33import (
44 "context"
55 "errors"
6+ "fmt"
7+ "sort"
68 "strings"
79
810 "github.com/404tk/cloudtoolkit/pkg/providers/volcengine/api"
@@ -35,7 +37,7 @@ func (d *Driver) GetResource(ctx context.Context) ([]schema.Host, error) {
3537 }
3638 tracker := processbar .NewRegionTracker ()
3739 defer tracker .Finish ()
38- got , _ := regionrun .ForEach (ctx , regions , 0 , tracker , func (ctx context.Context , r string ) ([]schema.Host , error ) {
40+ got , regionErrs := regionrun .ForEach (ctx , regions , 0 , tracker , func (ctx context.Context , r string ) ([]schema.Host , error ) {
3941 return paginate .Fetch [schema.Host , string ](ctx , func (ctx context.Context , token string ) (paginate.Page [schema.Host , string ], error ) {
4042 resp , err := client .DescribeInstances (ctx , r , 100 , token )
4143 if err != nil {
@@ -68,7 +70,7 @@ func (d *Driver) GetResource(ctx context.Context) ([]schema.Host, error) {
6870 })
6971 })
7072 list = append (list , got ... )
71- return list , nil
73+ return list , flattenRegionErrors ( regionErrs )
7274}
7375
7476func (d * Driver ) requireClient () (* api.Client , error ) {
@@ -102,3 +104,24 @@ func (d *Driver) requestRegion() string {
102104 }
103105 return region
104106}
107+
108+ func flattenRegionErrors (errs map [string ]error ) error {
109+ if len (errs ) == 0 {
110+ return nil
111+ }
112+ regions := make ([]string , 0 , len (errs ))
113+ for region := range errs {
114+ regions = append (regions , region )
115+ }
116+ sort .Strings (regions )
117+ parts := make ([]string , 0 , len (regions ))
118+ for _ , region := range regions {
119+ if err := errs [region ]; err != nil {
120+ parts = append (parts , fmt .Sprintf ("%s: %v" , region , err ))
121+ }
122+ }
123+ if len (parts ) == 0 {
124+ return nil
125+ }
126+ return fmt .Errorf ("partial region errors: %s" , strings .Join (parts , "; " ))
127+ }
0 commit comments