@@ -123,7 +123,7 @@ func (d *downloader) GetByLabel(label string) *TemplateInfo {
123
123
return nil
124
124
}
125
125
126
- func (d * downloader ) readTemplatesConfig () ([]TemplateInfo , error ) {
126
+ func (d * downloader ) readTemplatesConfig (client GetterClient , retryCount int ) ([]TemplateInfo , error ) {
127
127
file , err := os .Open (d .configPath )
128
128
if err != nil {
129
129
return nil , err
@@ -135,6 +135,24 @@ func (d *downloader) readTemplatesConfig() ([]TemplateInfo, error) {
135
135
repo := repository {}
136
136
137
137
if err := decoder .Decode (& repo ); err != nil {
138
+ // if an error occurs while decoding the yaml file, delete the file and try again based on the retry count
139
+ if retryCount > 0 {
140
+ // close the file before deleting it
141
+ file .Close ()
142
+
143
+ err = os .Remove (d .configPath )
144
+ if err != nil {
145
+ return nil , errors .WithMessage (err , "repository file " + d .configPath )
146
+ }
147
+
148
+ err = client .Get ()
149
+ if err != nil {
150
+ return nil , errors .WithMessage (err , "repository file " + d .configPath )
151
+ }
152
+
153
+ return d .readTemplatesConfig (client , retryCount - 1 )
154
+ }
155
+
138
156
return nil , errors .WithMessage (err , "repository file " + d .configPath )
139
157
}
140
158
@@ -166,7 +184,7 @@ func (d *downloader) repository() error {
166
184
return err
167
185
}
168
186
169
- list , err := d .readTemplatesConfig ()
187
+ list , err := d .readTemplatesConfig (client , 1 )
170
188
if err != nil {
171
189
return err
172
190
}
0 commit comments