Skip to content

Commit 4388cd4

Browse files
committed
instance.Init no longer return errors array.
They are printed directly inside the function through the feedback package.
1 parent 5b6398b commit 4388cd4

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

cli/core/search.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
7373
}
7474
}
7575

76-
for _, err := range instance.Init(inst) {
77-
feedback.Errorf(tr("Error initializing instance: %v"), err)
78-
}
76+
instance.Init(inst)
7977

8078
arguments := strings.ToLower(strings.Join(args, " "))
8179
logrus.Infof("Executing `arduino-cli core search` with args: '%s'", arguments)

cli/instance/instance.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package instance
1717

1818
import (
1919
"context"
20-
"errors"
2120
"os"
2221

2322
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -50,10 +49,7 @@ func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path) (*rpc.
5049
feedback.Errorf(tr("Error creating instance: %v"), err)
5150
os.Exit(errorcodes.ErrGeneric)
5251
}
53-
profile, errs := InitWithProfile(instance, profileName, sketchPath)
54-
for _, err := range errs {
55-
feedback.Errorf(tr("Error initializing instance: %v"), err)
56-
}
52+
profile := InitWithProfile(instance, profileName, sketchPath)
5753
return instance, profile
5854
}
5955

@@ -71,20 +67,18 @@ func Create() (*rpc.Instance, error) {
7167
// platform or library that we failed to load.
7268
// Package and library indexes files are automatically updated if the
7369
// CLI is run for the first time.
74-
func Init(instance *rpc.Instance) []error {
75-
_, errs := InitWithProfile(instance, "", nil)
76-
return errs
70+
func Init(instance *rpc.Instance) {
71+
InitWithProfile(instance, "", nil)
7772
}
7873

7974
// InitWithProfile initializes instance by loading libraries and platforms specified in the given profile of the given sketch.
8075
// In case of loading failures return a list of errors for each platform or library that we failed to load.
8176
// Required Package and library indexes files are automatically downloaded.
82-
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) (*rpc.Profile, []error) {
83-
errs := []error{}
84-
77+
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) *rpc.Profile {
8578
// In case the CLI is executed for the first time
8679
if err := FirstUpdate(instance); err != nil {
87-
return nil, append(errs, err)
80+
feedback.Errorf(tr("Error initializing instance: %v"), err)
81+
return nil
8882
}
8983

9084
downloadCallback := output.ProgressBar()
@@ -98,7 +92,7 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat
9892
var profile *rpc.Profile
9993
err := commands.Init(initReq, func(res *rpc.InitResponse) {
10094
if st := res.GetError(); st != nil {
101-
errs = append(errs, errors.New(st.Message))
95+
feedback.Errorf(tr("Error initializing instance: %v"), st.Message)
10296
}
10397

10498
if progress := res.GetInitProgress(); progress != nil {
@@ -115,10 +109,10 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat
115109
}
116110
})
117111
if err != nil {
118-
errs = append(errs, err)
112+
feedback.Errorf(tr("Error initializing instance: %v"), err)
119113
}
120114

121-
return profile, errs
115+
return profile
122116
}
123117

124118
// FirstUpdate downloads libraries and packages indexes if they don't exist.

cli/lib/search.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6969
os.Exit(errorcodes.ErrGeneric)
7070
}
7171

72-
for _, err := range instance.Init(inst) {
73-
feedback.Errorf(tr("Error initializing instance: %v"), err)
74-
}
72+
instance.Init(inst)
7573

7674
searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
7775
Instance: inst,

docs/UPGRADING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
Here you can find a list of migration guides to handle breaking changes between releases of the CLI.
44

5+
## 0.29.0
6+
7+
### Changes in golang functions `github.com/arduino/arduino-cli/cli/instance.Init` and `InitWithProfile`
8+
9+
The following functions:
10+
11+
```go
12+
func Init(instance *rpc.Instance) []error { }
13+
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) (*rpc.Profile, []error) { }
14+
```
15+
16+
no longer return the errors array:
17+
18+
```go
19+
func Init(instance *rpc.Instance) { }
20+
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) *rpc.Profile { }
21+
```
22+
23+
The errors are automatically sent to output via `feedback` package, as for the other `Init*` functions.
24+
525
## 0.28.0
626

727
### Breaking changes in libraries name handling

0 commit comments

Comments
 (0)