@@ -17,10 +17,14 @@ package instance
17
17
18
18
import (
19
19
"context"
20
+ "fmt"
21
+ "strings"
20
22
21
23
"github.com/arduino/arduino-cli/cli/output"
22
24
"github.com/arduino/arduino-cli/commands"
25
+ "github.com/arduino/arduino-cli/configuration"
23
26
rpc "github.com/arduino/arduino-cli/rpc/commands"
27
+ "github.com/arduino/go-paths-helper"
24
28
"github.com/pkg/errors"
25
29
"github.com/sirupsen/logrus"
26
30
)
@@ -51,9 +55,13 @@ func getInitResponse() (*rpc.InitResp, error) {
51
55
return nil , errors .Wrap (err , "creating instance" )
52
56
}
53
57
54
- // Init() succeeded but there were errors loading library indexes,
55
- // let's rescan and try again
56
- if resp .GetLibrariesIndexError () != "" {
58
+ // Gets the data directory to verify if library_index.json and package_index.json exist
59
+ dataDir := paths .New (configuration .Settings .GetString ("directories.data" ))
60
+
61
+ // The library_index.json file doesn't exists, that means the CLI is run for the first time
62
+ // so we proceed with the first update that downloads the file
63
+ libraryIndex := dataDir .Join ("library_index.json" )
64
+ if libraryIndex .NotExist () {
57
65
logrus .Warnf ("There were errors loading the library index, trying again..." )
58
66
59
67
// update all indexes
@@ -80,15 +88,11 @@ func getInitResponse() (*rpc.InitResp, error) {
80
88
resp .PlatformsIndexErrors = rescanResp .PlatformsIndexErrors
81
89
}
82
90
83
- // Init() succeeded but there were errors loading platform indexes,
84
- // let's rescan and try again
85
- if resp .GetPlatformsIndexErrors () != nil {
86
-
87
- // log each error
88
- for _ , err := range resp .GetPlatformsIndexErrors () {
89
- logrus .Errorf ("Error loading platform index: %v" , err )
90
- }
91
-
91
+ // The package_index.json file doesn't exists, that means the CLI is run for the first time,
92
+ // similarly to the library update we download that file and all the other package indexes
93
+ // from additional_urls
94
+ packageIndex := dataDir .Join ("package_index.json" )
95
+ if packageIndex .NotExist () {
92
96
// update platform index
93
97
_ , err := commands .UpdateIndex (context .Background (),
94
98
& rpc.UpdateIndexReq {Instance : resp .GetInstance ()}, output .ProgressBar ())
@@ -124,8 +128,7 @@ func checkPlatformErrors(resp *rpc.InitResp) error {
124
128
for _ , err := range resp .GetPlatformsIndexErrors () {
125
129
logrus .Errorf ("Error loading platform index: %v" , err )
126
130
}
127
- // return
128
- return errors .New ("There were errors loading platform indexes" )
131
+ return fmt .Errorf ("error loading platform index: \n %v" , strings .Join (resp .GetPlatformsIndexErrors (), "\n " ))
129
132
}
130
133
131
134
return nil
0 commit comments