Skip to content

Commit 478205e

Browse files
committed
Handled package name change cause of errors move
1 parent cff44e6 commit 478205e

33 files changed

+235
-205
lines changed

cli/core/upgrade.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
"fmt"
2222
"os"
2323

24+
"github.com/arduino/arduino-cli/arduino"
2425
"github.com/arduino/arduino-cli/cli/arguments"
2526
"github.com/arduino/arduino-cli/cli/errorcodes"
2627
"github.com/arduino/arduino-cli/cli/feedback"
2728
"github.com/arduino/arduino-cli/cli/instance"
2829
"github.com/arduino/arduino-cli/cli/output"
29-
"github.com/arduino/arduino-cli/commands"
3030
"github.com/arduino/arduino-cli/commands/core"
3131
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3232
"github.com/sirupsen/logrus"
@@ -97,7 +97,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
9797
}
9898

9999
if _, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress()); err != nil {
100-
if errors.Is(err, &commands.PlatformAlreadyAtTheLatestVersionError{}) {
100+
if errors.Is(err, &arduino.PlatformAlreadyAtTheLatestVersionError{}) {
101101
feedback.Print(err.Error())
102102
continue
103103
}

commands/board/attach.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25+
"github.com/arduino/arduino-cli/arduino"
2526
"github.com/arduino/arduino-cli/arduino/cores"
2627
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2728
"github.com/arduino/arduino-cli/arduino/sketch"
@@ -38,15 +39,15 @@ var tr = i18n.Tr
3839
func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.TaskProgressCB) (*rpc.BoardAttachResponse, error) {
3940
pm := commands.GetPackageManager(req.GetInstance().GetId())
4041
if pm == nil {
41-
return nil, &commands.InvalidInstanceError{}
42+
return nil, &arduino.InvalidInstanceError{}
4243
}
4344
var sketchPath *paths.Path
4445
if req.GetSketchPath() != "" {
4546
sketchPath = paths.New(req.GetSketchPath())
4647
}
4748
sk, err := sketch.New(sketchPath)
4849
if err != nil {
49-
return nil, &commands.CantOpenSketchError{Cause: err}
50+
return nil, &arduino.CantOpenSketchError{Cause: err}
5051
}
5152

5253
boardURI := req.GetBoardUri()
@@ -62,7 +63,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
6263
} else {
6364
deviceURI, err := url.Parse(boardURI)
6465
if err != nil {
65-
return nil, &commands.InvalidArgumentError{Message: tr("Invalid Device URL format"), Cause: err}
66+
return nil, &arduino.InvalidArgumentError{Message: tr("Invalid Device URL format"), Cause: err}
6667
}
6768

6869
var findBoardFunc func(*packagemanager.PackageManager, *discovery.Monitor, *url.URL) *cores.Board
@@ -72,7 +73,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
7273
case "http", "https", "tcp", "udp":
7374
findBoardFunc = findNetworkConnectedBoard
7475
default:
75-
return nil, &commands.InvalidArgumentError{Message: tr("Invalid device port type provided")}
76+
return nil, &arduino.InvalidArgumentError{Message: tr("Invalid device port type provided")}
7677
}
7778

7879
duration, err := time.ParseDuration(req.GetSearchTimeout())
@@ -88,7 +89,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
8889
// TODO: Handle the case when no board is found.
8990
board := findBoardFunc(pm, monitor, deviceURI)
9091
if board == nil {
91-
return nil, &commands.InvalidArgumentError{Message: tr("No supported board found at %s", deviceURI)}
92+
return nil, &arduino.InvalidArgumentError{Message: tr("No supported board found at %s", deviceURI)}
9293
}
9394
taskCB(&rpc.TaskProgress{Name: tr("Board found: %s", board.Name())})
9495

@@ -103,7 +104,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
103104

104105
err = sk.ExportMetadata()
105106
if err != nil {
106-
return nil, &commands.PermissionDeniedError{Message: tr("Cannot export sketch metadata"), Cause: err}
107+
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot export sketch metadata"), Cause: err}
107108
}
108109
taskCB(&rpc.TaskProgress{Name: tr("Selected fqbn: %s", sk.Metadata.CPU.Fqbn), Completed: true})
109110
return &rpc.BoardAttachResponse{}, nil

commands/board/details.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package board
1818
import (
1919
"context"
2020

21+
"github.com/arduino/arduino-cli/arduino"
2122
"github.com/arduino/arduino-cli/arduino/cores"
2223
"github.com/arduino/arduino-cli/commands"
2324
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -28,17 +29,17 @@ import (
2829
func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetailsResponse, error) {
2930
pm := commands.GetPackageManager(req.GetInstance().GetId())
3031
if pm == nil {
31-
return nil, &commands.InvalidInstanceError{}
32+
return nil, &arduino.InvalidInstanceError{}
3233
}
3334

3435
fqbn, err := cores.ParseFQBN(req.GetFqbn())
3536
if err != nil {
36-
return nil, &commands.InvalidFQBNError{Cause: err}
37+
return nil, &arduino.InvalidFQBNError{Cause: err}
3738
}
3839

3940
boardPackage, boardPlatform, board, boardProperties, boardRefPlatform, err := pm.ResolveFQBN(fqbn)
4041
if err != nil {
41-
return nil, &commands.UnknownFQBNError{Cause: err}
42+
return nil, &arduino.UnknownFQBNError{Cause: err}
4243
}
4344

4445
details := &rpc.BoardDetailsResponse{}

commands/board/list.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/arduino/arduino-cli/arduino"
2829
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2930
"github.com/arduino/arduino-cli/arduino/discovery"
3031
"github.com/arduino/arduino-cli/commands"
@@ -143,7 +144,7 @@ func identify(pm *packagemanager.PackageManager, port *discovery.Port) ([]*rpc.B
143144
logrus.Debug("Board not recognized")
144145
} else if err != nil {
145146
// this is bad, bail out
146-
return nil, &commands.UnavailableError{Message: tr("Error getting board info from Arduino Cloud")}
147+
return nil, &arduino.UnavailableError{Message: tr("Error getting board info from Arduino Cloud")}
147148
}
148149

149150
// add a DetectedPort entry in any case: the `Boards` field will
@@ -188,15 +189,15 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
188189

189190
pm := commands.GetPackageManager(req.GetInstance().Id)
190191
if pm == nil {
191-
return nil, &commands.InvalidInstanceError{}
192+
return nil, &arduino.InvalidInstanceError{}
192193
}
193194

194195
dm := pm.DiscoveryManager()
195196
if errs := dm.RunAll(); len(errs) > 0 {
196-
return nil, &commands.UnavailableError{Message: tr("Error starting board discoveries"), Cause: fmt.Errorf("%v", errs)}
197+
return nil, &arduino.UnavailableError{Message: tr("Error starting board discoveries"), Cause: fmt.Errorf("%v", errs)}
197198
}
198199
if errs := dm.StartAll(); len(errs) > 0 {
199-
return nil, &commands.UnavailableError{Message: tr("Error starting board discoveries"), Cause: fmt.Errorf("%v", errs)}
200+
return nil, &arduino.UnavailableError{Message: tr("Error starting board discoveries"), Cause: fmt.Errorf("%v", errs)}
200201
}
201202
defer func() {
202203
if errs := dm.StopAll(); len(errs) > 0 {
@@ -208,7 +209,7 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
208209
retVal := []*rpc.DetectedPort{}
209210
ports, errs := pm.DiscoveryManager().List()
210211
if len(errs) > 0 {
211-
return nil, &commands.UnavailableError{Message: tr("Error getting board list"), Cause: fmt.Errorf("%v", errs)}
212+
return nil, &arduino.UnavailableError{Message: tr("Error getting board list"), Cause: fmt.Errorf("%v", errs)}
212213
}
213214
for _, port := range ports {
214215
boards, err := identify(pm, port)
@@ -237,7 +238,7 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
237238
runErrs := dm.RunAll()
238239
if len(runErrs) == len(dm.IDs()) {
239240
// All discoveries failed to run, we can't do anything
240-
return nil, &commands.UnavailableError{Message: tr("Error starting board discoveries"), Cause: fmt.Errorf("%v", runErrs)}
241+
return nil, &arduino.UnavailableError{Message: tr("Error starting board discoveries"), Cause: fmt.Errorf("%v", runErrs)}
241242
}
242243

243244
eventsChan, errs := dm.StartSyncAll()

commands/board/listall.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"strings"
2121

22+
"github.com/arduino/arduino-cli/arduino"
2223
"github.com/arduino/arduino-cli/arduino/utils"
2324
"github.com/arduino/arduino-cli/commands"
2425
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -28,7 +29,7 @@ import (
2829
func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) {
2930
pm := commands.GetPackageManager(req.GetInstance().GetId())
3031
if pm == nil {
31-
return nil, &commands.InvalidInstanceError{}
32+
return nil, &arduino.InvalidInstanceError{}
3233
}
3334

3435
searchArgs := strings.Join(req.GetSearchArgs(), " ")

commands/board/search.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"sort"
2121
"strings"
2222

23+
"github.com/arduino/arduino-cli/arduino"
2324
"github.com/arduino/arduino-cli/arduino/utils"
2425
"github.com/arduino/arduino-cli/commands"
2526
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -32,7 +33,7 @@ import (
3233
func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchResponse, error) {
3334
pm := commands.GetPackageManager(req.GetInstance().GetId())
3435
if pm == nil {
35-
return nil, &commands.InvalidInstanceError{}
36+
return nil, &arduino.InvalidInstanceError{}
3637
}
3738

3839
res := &rpc.BoardSearchResponse{Boards: []*rpc.BoardListItem{}}

commands/bundled_tools.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package commands
1717

1818
import (
19+
"github.com/arduino/arduino-cli/arduino"
1920
"github.com/arduino/arduino-cli/arduino/cores"
2021
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2122
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -49,7 +50,7 @@ func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.To
4950
err := pm.InstallTool(toolRelease)
5051
if err != nil {
5152
log.WithError(err).Warn("Cannot install tool")
52-
return &FailedInstallError{Message: tr("Cannot install tool %s", toolRelease), Cause: err}
53+
return &arduino.FailedInstallError{Message: tr("Cannot install tool %s", toolRelease), Cause: err}
5354
}
5455
log.Info("Tool installed")
5556
taskCB(&rpc.TaskProgress{Message: tr("%s installed", toolRelease), Completed: true})

commands/compile/compile.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ package compile
1717

1818
import (
1919
"context"
20-
"errors"
20+
"fmt"
2121
"io"
2222
"path/filepath"
2323
"sort"
2424
"strconv"
2525
"strings"
2626

27+
"github.com/arduino/arduino-cli/arduino"
2728
bldr "github.com/arduino/arduino-cli/arduino/builder"
2829
"github.com/arduino/arduino-cli/arduino/cores"
2930
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
@@ -89,29 +90,29 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
8990

9091
pm := commands.GetPackageManager(req.GetInstance().GetId())
9192
if pm == nil {
92-
return nil, &commands.InvalidInstanceError{}
93+
return nil, &arduino.InvalidInstanceError{}
9394
}
9495

9596
logrus.Tracef("Compile %s for %s started", req.GetSketchPath(), req.GetFqbn())
9697
if req.GetSketchPath() == "" {
97-
return nil, &commands.MissingSketchPathError{}
98+
return nil, &arduino.MissingSketchPathError{}
9899
}
99100
sketchPath := paths.New(req.GetSketchPath())
100101
sk, err := sketch.New(sketchPath)
101102
if err != nil {
102-
return nil, &commands.CantOpenSketchError{Cause: err}
103+
return nil, &arduino.CantOpenSketchError{Cause: err}
103104
}
104105

105106
fqbnIn := req.GetFqbn()
106107
if fqbnIn == "" && sk != nil && sk.Metadata != nil {
107108
fqbnIn = sk.Metadata.CPU.Fqbn
108109
}
109110
if fqbnIn == "" {
110-
return nil, &commands.MissingFQBNError{}
111+
return nil, &arduino.MissingFQBNError{}
111112
}
112113
fqbn, err := cores.ParseFQBN(fqbnIn)
113114
if err != nil {
114-
return nil, &commands.InvalidFQBNError{Cause: err}
115+
return nil, &arduino.InvalidFQBNError{Cause: err}
115116
}
116117

117118
targetPlatform := pm.FindPlatform(&packagemanager.PlatformReference{
@@ -124,7 +125,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
124125
// "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
125126
// version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
126127
// feedback.Error(errorMessage)
127-
return nil, &commands.PlatformNotFound{Platform: targetPlatform.String(), Cause: errors.New(tr("platform not installed"))}
128+
return nil, &arduino.PlatformNotFound{Platform: targetPlatform.String(), Cause: fmt.Errorf(tr("platform not installed"))}
128129
}
129130

130131
builderCtx := &types.Context{}
@@ -147,7 +148,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
147148
builderCtx.BuildPath = paths.New(req.GetBuildPath()).Canonical()
148149
}
149150
if err = builderCtx.BuildPath.MkdirAll(); err != nil {
150-
return nil, &commands.PermissionDeniedError{Message: tr("Cannot create build directory"), Cause: err}
151+
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build directory"), Cause: err}
151152
}
152153
builderCtx.CompilationDatabase = bldr.NewCompilationDatabase(
153154
builderCtx.BuildPath.Join("compile_commands.json"),
@@ -177,7 +178,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
177178
builderCtx.BuildCachePath = paths.New(req.GetBuildCachePath())
178179
err = builderCtx.BuildCachePath.MkdirAll()
179180
if err != nil {
180-
return nil, &commands.PermissionDeniedError{Message: tr("Cannot create build cache directory"), Cause: err}
181+
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build cache directory"), Cause: err}
181182
}
182183
}
183184

@@ -222,20 +223,20 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
222223
if req.GetShowProperties() {
223224
compileErr := builder.RunParseHardwareAndDumpBuildProperties(builderCtx)
224225
if compileErr != nil {
225-
compileErr = &commands.CompileFailedError{Message: err.Error()}
226+
compileErr = &arduino.CompileFailedError{Message: err.Error()}
226227
}
227228
return r, compileErr
228229
} else if req.GetPreprocess() {
229230
compileErr := builder.RunPreprocess(builderCtx)
230231
if compileErr != nil {
231-
compileErr = &commands.CompileFailedError{Message: err.Error()}
232+
compileErr = &arduino.CompileFailedError{Message: err.Error()}
232233
}
233234
return r, compileErr
234235
}
235236

236237
// if it's a regular build, go on...
237238
if err := builder.RunBuilder(builderCtx); err != nil {
238-
return r, &commands.CompileFailedError{Message: err.Error()}
239+
return r, &arduino.CompileFailedError{Message: err.Error()}
239240
}
240241

241242
// If the export directory is set we assume you want to export the binaries
@@ -257,17 +258,17 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
257258
}
258259
logrus.WithField("path", exportPath).Trace("Saving sketch to export path.")
259260
if err := exportPath.MkdirAll(); err != nil {
260-
return r, &commands.PermissionDeniedError{Message: tr("Error creating output dir"), Cause: err}
261+
return r, &arduino.PermissionDeniedError{Message: tr("Error creating output dir"), Cause: err}
261262
}
262263

263264
// Copy all "sketch.ino.*" artifacts to the export directory
264265
baseName, ok := builderCtx.BuildProperties.GetOk("build.project_name") // == "sketch.ino"
265266
if !ok {
266-
return r, &commands.MissingPlatformPropertyError{Property: "build.project_name"}
267+
return r, &arduino.MissingPlatformPropertyError{Property: "build.project_name"}
267268
}
268269
buildFiles, err := builderCtx.BuildPath.ReadDir()
269270
if err != nil {
270-
return r, &commands.PermissionDeniedError{Message: tr("Error reading build directory"), Cause: err}
271+
return r, &arduino.PermissionDeniedError{Message: tr("Error reading build directory"), Cause: err}
271272
}
272273
buildFiles.FilterPrefix(baseName)
273274
for _, buildFile := range buildFiles {
@@ -277,7 +278,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
277278
WithField("dest", exportedFile).
278279
Trace("Copying artifact.")
279280
if err = buildFile.CopyTo(exportedFile); err != nil {
280-
return r, &commands.PermissionDeniedError{Message: tr("Error copying output file %s", buildFile), Cause: err}
281+
return r, &arduino.PermissionDeniedError{Message: tr("Error copying output file %s", buildFile), Cause: err}
281282
}
282283
}
283284
}
@@ -286,7 +287,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
286287
for _, lib := range builderCtx.ImportedLibraries {
287288
rpcLib, err := lib.ToRPCLibrary()
288289
if err != nil {
289-
return r, &commands.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Name), Cause: err}
290+
return r, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Name), Cause: err}
290291
}
291292
importedLibs = append(importedLibs, rpcLib)
292293
}

0 commit comments

Comments
 (0)