@@ -95,9 +95,9 @@ func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) {
95
95
return nil , fmt .Errorf ("parsing url %s: %s" , rawurl , err )
96
96
}
97
97
}
98
- pm , lm , err := createInstance (ctx , config , req .GetLibraryManagerOnly ())
98
+ pm , lm , reqPltIndex , reqLibIndex , err := createInstance (ctx , config , req .GetLibraryManagerOnly ())
99
99
if err != nil {
100
- return nil , fmt .Errorf ("Impossible create instance" )
100
+ return nil , fmt .Errorf ("cannot initialize package manager: %s" , err )
101
101
}
102
102
instance := & CoreInstance {
103
103
config : config ,
@@ -109,7 +109,9 @@ func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) {
109
109
instances [handle ] = instance
110
110
111
111
return & rpc.InitResp {
112
- Instance : & rpc.Instance {Id : handle },
112
+ Instance : & rpc.Instance {Id : handle },
113
+ PlatformsIndexErrors : reqPltIndex ,
114
+ LibrariesIndexError : reqLibIndex ,
113
115
}, nil
114
116
}
115
117
@@ -161,35 +163,34 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
161
163
162
164
tmpFile , err := ioutil .TempFile ("" , "" )
163
165
if err != nil {
164
- return nil , fmt .Errorf ("Error creating temp file for download" , err )
165
-
166
+ return nil , fmt .Errorf ("creating temp file for download: %s" , err )
166
167
}
167
168
if err := tmpFile .Close (); err != nil {
168
- return nil , fmt .Errorf ("Error creating temp file for download" , err )
169
+ return nil , fmt .Errorf ("creating temp file for download: %s " , err )
169
170
}
170
171
tmp := paths .New (tmpFile .Name ())
171
172
defer tmp .Remove ()
172
173
173
174
d , err := downloader .Download (tmp .String (), URL .String ())
174
175
if err != nil {
175
- return nil , fmt .Errorf ("Error downloading index " + URL . String () , err )
176
+ return nil , fmt .Errorf ("downloading index %s: %s" , URL , err )
176
177
}
177
178
coreIndexPath := indexpath .Join (path .Base (URL .Path ))
178
179
Download (d , "Updating index: " + coreIndexPath .Base (), downloadCB )
179
180
if d .Error () != nil {
180
- return nil , fmt .Errorf ("Error downloading index " + URL . String () , d .Error ())
181
+ return nil , fmt .Errorf ("downloading index %s: %s" , URL , d .Error ())
181
182
}
182
183
183
184
if _ , err := packageindex .LoadIndex (tmp ); err != nil {
184
- return nil , fmt .Errorf ("Invalid package index in " + URL . String () , err )
185
+ return nil , fmt .Errorf ("invalid package index in %s: %s" , URL , err )
185
186
}
186
187
187
188
if err := indexpath .MkdirAll (); err != nil {
188
- return nil , fmt .Errorf ("Can 't create data directory " + indexpath . String () , err )
189
+ return nil , fmt .Errorf ("can 't create data directory %s: %s" , indexpath , err )
189
190
}
190
191
191
192
if err := tmp .CopyTo (coreIndexPath ); err != nil {
192
- return nil , fmt .Errorf ("Error saving downloaded index " + URL . String () , err )
193
+ return nil , fmt .Errorf ("saving downloaded index %s: %s" , URL , err )
193
194
}
194
195
}
195
196
Rescan (ctx , & rpc.RescanReq {Instance : req .Instance })
@@ -203,17 +204,21 @@ func Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) {
203
204
return nil , fmt .Errorf ("invalid handle" )
204
205
}
205
206
206
- pm , lm , err := createInstance (ctx , coreInstance .config , coreInstance .getLibOnly )
207
+ pm , lm , reqPltIndex , reqLibIndex , err := createInstance (ctx , coreInstance .config , coreInstance .getLibOnly )
207
208
if err != nil {
208
- return nil , fmt .Errorf ("rescanning: %s" , err )
209
+ return nil , fmt .Errorf ("rescanning filesystem : %s" , err )
209
210
}
210
211
coreInstance .pm = pm
211
212
coreInstance .lm = lm
212
- return & rpc.RescanResp {}, nil
213
+ return & rpc.RescanResp {
214
+ PlatformsIndexErrors : reqPltIndex ,
215
+ LibrariesIndexError : reqLibIndex ,
216
+ }, nil
213
217
}
214
218
215
- func createInstance (ctx context.Context , config * configs.Configuration , getLibOnly bool ) (* packagemanager.PackageManager , * librariesmanager.LibrariesManager , error ) {
219
+ func createInstance (ctx context.Context , config * configs.Configuration , getLibOnly bool ) (* packagemanager.PackageManager , * librariesmanager.LibrariesManager , [] string , string , error ) {
216
220
var pm * packagemanager.PackageManager
221
+ platformIndexErrors := []string {}
217
222
if ! getLibOnly {
218
223
pm = packagemanager .NewPackageManager (
219
224
config .IndexesDir (),
@@ -223,14 +228,17 @@ func createInstance(ctx context.Context, config *configs.Configuration, getLibOn
223
228
224
229
for _ , URL := range config .BoardManagerAdditionalUrls {
225
230
if err := pm .LoadPackageIndex (URL ); err != nil {
226
- return nil , nil , fmt . Errorf ( "loading " + URL . String () + " package index: %s" , err )
231
+ platformIndexErrors = append ( platformIndexErrors , err . Error () )
227
232
}
228
233
}
229
234
230
235
if err := pm .LoadHardware (config ); err != nil {
231
- return nil , nil , fmt .Errorf ("loading hardware packages: %s" , err )
236
+ return nil , nil , nil , "" , fmt .Errorf ("loading hardware packages: %s" , err )
232
237
}
233
238
}
239
+ if len (platformIndexErrors ) == 0 {
240
+ platformIndexErrors = nil
241
+ }
234
242
235
243
// Initialize library manager
236
244
// --------------------------
@@ -258,20 +266,16 @@ func createInstance(ctx context.Context, config *configs.Configuration, getLibOn
258
266
}
259
267
260
268
// Load index and auto-update it if needed
269
+ librariesIndexError := ""
261
270
if err := lm .LoadIndex (); err != nil {
262
- UpdateLibrariesIndex (ctx , lm , func (curr * rpc.DownloadProgress ) {
263
- fmt .Printf (">> %+v\n " , curr )
264
- })
265
- if err := lm .LoadIndex (); err != nil {
266
- return nil , nil , fmt .Errorf ("loading libraries index: %s" , err )
267
- }
271
+ librariesIndexError = err .Error ()
268
272
}
269
273
270
274
// Scan for libraries
271
275
if err := lm .RescanLibraries (); err != nil {
272
- return nil , nil , fmt .Errorf ("libraries rescan: %s" , err )
276
+ return nil , nil , nil , "" , fmt .Errorf ("libraries rescan: %s" , err )
273
277
}
274
- return pm , lm , nil
278
+ return pm , lm , platformIndexErrors , librariesIndexError , nil
275
279
}
276
280
277
281
func Download (d * downloader.Downloader , label string , downloadCB DownloadProgressCB ) error {
0 commit comments