@@ -22,6 +22,7 @@ import (
22
22
"strings"
23
23
"time"
24
24
25
+ "github.com/arduino/arduino-cli/arduino"
25
26
"github.com/arduino/arduino-cli/arduino/cores"
26
27
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
27
28
"github.com/arduino/arduino-cli/arduino/sketch"
@@ -38,15 +39,15 @@ var tr = i18n.Tr
38
39
func Attach (ctx context.Context , req * rpc.BoardAttachRequest , taskCB commands.TaskProgressCB ) (* rpc.BoardAttachResponse , error ) {
39
40
pm := commands .GetPackageManager (req .GetInstance ().GetId ())
40
41
if pm == nil {
41
- return nil , & commands .InvalidInstanceError {}
42
+ return nil , & arduino .InvalidInstanceError {}
42
43
}
43
44
var sketchPath * paths.Path
44
45
if req .GetSketchPath () != "" {
45
46
sketchPath = paths .New (req .GetSketchPath ())
46
47
}
47
48
sk , err := sketch .New (sketchPath )
48
49
if err != nil {
49
- return nil , & commands .CantOpenSketchError {Cause : err }
50
+ return nil , & arduino .CantOpenSketchError {Cause : err }
50
51
}
51
52
52
53
boardURI := req .GetBoardUri ()
@@ -62,7 +63,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
62
63
} else {
63
64
deviceURI , err := url .Parse (boardURI )
64
65
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 }
66
67
}
67
68
68
69
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
72
73
case "http" , "https" , "tcp" , "udp" :
73
74
findBoardFunc = findNetworkConnectedBoard
74
75
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" )}
76
77
}
77
78
78
79
duration , err := time .ParseDuration (req .GetSearchTimeout ())
@@ -88,7 +89,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
88
89
// TODO: Handle the case when no board is found.
89
90
board := findBoardFunc (pm , monitor , deviceURI )
90
91
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 )}
92
93
}
93
94
taskCB (& rpc.TaskProgress {Name : tr ("Board found: %s" , board .Name ())})
94
95
@@ -103,7 +104,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachRequest, taskCB commands.Ta
103
104
104
105
err = sk .ExportMetadata ()
105
106
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 }
107
108
}
108
109
taskCB (& rpc.TaskProgress {Name : tr ("Selected fqbn: %s" , sk .Metadata .CPU .Fqbn ), Completed : true })
109
110
return & rpc.BoardAttachResponse {}, nil
0 commit comments