Skip to content

Commit d3356cc

Browse files
committed
UpdateIndex gRPC call does not stop at the first error
1 parent 1da3b29 commit d3356cc

File tree

10 files changed

+890
-700
lines changed

10 files changed

+890
-700
lines changed

Diff for: cli/core/search.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6767
}
6868

6969
if indexesNeedUpdating(indexUpdateInterval) {
70-
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{
71-
Instance: inst,
72-
}, output.ProgressBar())
70+
err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{Instance: inst},
71+
output.ProgressBar(),
72+
output.PrintErrorFromDownloadResult(tr("Error updating index")))
7373
if err != nil {
74-
feedback.Errorf(tr("Error updating index: %v"), err)
7574
os.Exit(errorcodes.ErrGeneric)
7675
}
7776
}

Diff for: cli/core/update_index.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"os"
2121

2222
"github.com/arduino/arduino-cli/cli/errorcodes"
23-
"github.com/arduino/arduino-cli/cli/feedback"
2423
"github.com/arduino/arduino-cli/cli/instance"
2524
"github.com/arduino/arduino-cli/cli/output"
2625
"github.com/arduino/arduino-cli/commands"
@@ -45,11 +44,10 @@ func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
4544
inst := instance.CreateInstanceAndRunFirstUpdate()
4645
logrus.Info("Executing `arduino-cli core update-index`")
4746

48-
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{
49-
Instance: inst,
50-
}, output.ProgressBar())
47+
err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexRequest{Instance: inst},
48+
output.ProgressBar(),
49+
output.PrintErrorFromDownloadResult(tr("Error updating index")))
5150
if err != nil {
52-
feedback.Errorf(tr("Error updating index: %v"), err)
5351
os.Exit(errorcodes.ErrGeneric)
5452
}
5553
}

Diff for: cli/instance/instance.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ func FirstUpdate(instance *rpc.Instance) error {
152152
// similarly to the library update we download that file and all the other package indexes
153153
// from additional_urls
154154
if packageIndex.NotExist() {
155-
_, err := commands.UpdateIndex(context.Background(),
155+
err := commands.UpdateIndex(context.Background(),
156156
&rpc.UpdateIndexRequest{
157157
Instance: instance,
158158
IgnoreCustomPackageIndexes: true,
159159
},
160160
output.ProgressBar(),
161-
)
161+
output.PrintErrorFromDownloadResult(tr("Error updating index")))
162162
if err != nil {
163163
return err
164164
}

Diff for: cli/output/rpc_progress.go

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package output
1818
import (
1919
"fmt"
2020

21+
"github.com/arduino/arduino-cli/cli/feedback"
2122
"github.com/arduino/arduino-cli/i18n"
2223
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2324
"github.com/cmaglie/pb"
@@ -40,6 +41,21 @@ func ProgressBar() rpc.DownloadProgressCB {
4041
}
4142
}
4243

44+
// PrintErrorFromDownloadResult returns a DownloadResultCB that only prints
45+
// the errors with the give message prefixed.
46+
func PrintErrorFromDownloadResult(msg string) rpc.DownloadResultCB {
47+
if OutputFormat != "json" {
48+
return func(res *rpc.DownloadResult) {
49+
if !res.GetSuccessful() {
50+
feedback.Errorf("%s: %s", msg, res.GetError())
51+
}
52+
}
53+
}
54+
return func(res *rpc.DownloadResult) {
55+
// XXX: Output result in JSON?
56+
}
57+
}
58+
4359
// TaskProgress returns a TaskProgressCB that prints the task progress.
4460
// If JSON output format has been selected, the callback outputs nothing.
4561
func TaskProgress() rpc.TaskProgressCB {

Diff for: cli/update/update.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ func runUpdateCommand(cmd *cobra.Command, args []string) {
5656
inst := instance.CreateInstanceAndRunFirstUpdate()
5757
logrus.Info("Executing `arduino-cli update`")
5858

59-
err := commands.UpdateCoreLibrariesIndex(context.Background(), &rpc.UpdateCoreLibrariesIndexRequest{
60-
Instance: inst,
61-
}, output.ProgressBar())
59+
err := commands.UpdateCoreLibrariesIndex(context.Background(), &rpc.UpdateCoreLibrariesIndexRequest{Instance: inst},
60+
output.ProgressBar(),
61+
output.PrintErrorFromDownloadResult(tr("Error updating index")))
6262
if err != nil {
6363
feedback.Errorf(tr("Error updating core and libraries index: %v"), err)
6464
os.Exit(errorcodes.ErrGeneric)

Diff for: commands/daemon/daemon.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ func (s *ArduinoCoreServerImpl) Destroy(ctx context.Context, req *rpc.DestroyReq
161161

162162
// UpdateIndex FIXMEDOC
163163
func (s *ArduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream rpc.ArduinoCoreService_UpdateIndexServer) error {
164-
resp, err := commands.UpdateIndex(stream.Context(), req,
165-
func(p *rpc.DownloadProgress) { stream.Send(&rpc.UpdateIndexResponse{DownloadProgress: p}) },
164+
err := commands.UpdateIndex(stream.Context(), req,
165+
func(p *rpc.DownloadProgress) {
166+
stream.Send(&rpc.UpdateIndexResponse{Message: &rpc.UpdateIndexResponse_DownloadProgress{DownloadProgress: p}})
167+
},
168+
func(r *rpc.DownloadResult) {
169+
stream.Send(&rpc.UpdateIndexResponse{Message: &rpc.UpdateIndexResponse_DownloadResult{DownloadResult: r}})
170+
},
166171
)
167-
if err != nil {
168-
return convertErrorToRPCStatus(err)
169-
}
170-
return stream.Send(resp)
172+
return convertErrorToRPCStatus(err)
171173
}
172174

173175
// UpdateLibrariesIndex FIXMEDOC
@@ -185,6 +187,7 @@ func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
185187
func (s *ArduinoCoreServerImpl) UpdateCoreLibrariesIndex(req *rpc.UpdateCoreLibrariesIndexRequest, stream rpc.ArduinoCoreService_UpdateCoreLibrariesIndexServer) error {
186188
err := commands.UpdateCoreLibrariesIndex(stream.Context(), req,
187189
func(p *rpc.DownloadProgress) { stream.Send(&rpc.UpdateCoreLibrariesIndexResponse{DownloadProgress: p}) },
190+
func(res *rpc.DownloadResult) { /* ignore */ },
188191
)
189192
if err != nil {
190193
return convertErrorToRPCStatus(err)

Diff for: commands/instances.go

+36-8
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
490490
}
491491

492492
// UpdateIndex FIXMEDOC
493-
func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rpc.DownloadProgressCB) (*rpc.UpdateIndexResponse, error) {
493+
func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rpc.DownloadProgressCB, downloadResultCB rpc.DownloadResultCB) error {
494494
if instances.GetInstance(req.GetInstance().GetId()) == nil {
495-
return nil, &arduino.InvalidInstanceError{}
495+
return &arduino.InvalidInstanceError{}
496496
}
497497

498498
indexpath := configuration.DataDir(configuration.Settings)
@@ -501,11 +501,18 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
501501
if !req.GetIgnoreCustomPackageIndexes() {
502502
urls = append(urls, configuration.Settings.GetStringSlice("board_manager.additional_urls")...)
503503
}
504+
505+
failed := false
504506
for _, u := range urls {
505507
logrus.Info("URL: ", u)
506508
URL, err := utils.URLParse(u)
507509
if err != nil {
508510
logrus.Warnf("unable to parse additional URL: %s", u)
511+
downloadResultCB(&rpc.DownloadResult{
512+
Url: u,
513+
Error: fmt.Sprintf("%s: %v", tr("Unable to parse URL"), err),
514+
})
515+
failed = true
509516
continue
510517
}
511518

@@ -514,7 +521,12 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
514521
if URL.Scheme == "file" {
515522
path := paths.New(URL.Path)
516523
if _, err := packageindex.LoadIndexNoSign(path); err != nil {
517-
return nil, &arduino.InvalidArgumentError{Message: tr("Invalid package index in %s", path), Cause: err}
524+
downloadResultCB(&rpc.DownloadResult{
525+
Url: u,
526+
Error: fmt.Sprintf("%s: %v", tr("Invalid package index in %s", path), err),
527+
})
528+
failed = true
529+
continue
518530
}
519531

520532
fi, _ := os.Stat(path.String())
@@ -523,6 +535,10 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
523535
TotalSize: fi.Size(),
524536
})
525537
downloadCB(&rpc.DownloadProgress{Completed: true})
538+
downloadResultCB(&rpc.DownloadResult{
539+
Url: u,
540+
Successful: true,
541+
})
526542
continue
527543
}
528544

@@ -534,18 +550,30 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
534550
indexResource.SignatureURL.Path += ".sig"
535551
}
536552
if err := indexResource.Download(indexpath, downloadCB); err != nil {
537-
return nil, err
553+
downloadResultCB(&rpc.DownloadResult{
554+
Url: u,
555+
Error: err.Error(),
556+
})
557+
failed = true
538558
}
559+
560+
downloadResultCB(&rpc.DownloadResult{
561+
Url: u,
562+
Successful: true,
563+
})
539564
}
540565

541-
return &rpc.UpdateIndexResponse{}, nil
566+
if failed {
567+
return &arduino.FailedDownloadError{Message: tr("Some indexes could not be updated.")}
568+
}
569+
return nil
542570
}
543571

544572
// UpdateCoreLibrariesIndex updates both Cores and Libraries indexes
545-
func UpdateCoreLibrariesIndex(ctx context.Context, req *rpc.UpdateCoreLibrariesIndexRequest, downloadCB rpc.DownloadProgressCB) error {
546-
_, err := UpdateIndex(ctx, &rpc.UpdateIndexRequest{
573+
func UpdateCoreLibrariesIndex(ctx context.Context, req *rpc.UpdateCoreLibrariesIndexRequest, downloadCB rpc.DownloadProgressCB, downloadResultCB rpc.DownloadResultCB) error {
574+
err := UpdateIndex(ctx, &rpc.UpdateIndexRequest{
547575
Instance: req.Instance,
548-
}, downloadCB)
576+
}, downloadCB, downloadResultCB)
549577
if err != nil {
550578
return err
551579
}

0 commit comments

Comments
 (0)