@@ -51,7 +51,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
51
51
// FIXME: make a specification on how a port is specified via command line
52
52
port := req .GetPort ()
53
53
if port == "" {
54
- return nil , fmt .Errorf ("No port provided. " )
54
+ return nil , fmt .Errorf ("No port provided" )
55
55
}
56
56
57
57
fqbnIn := req .GetFqbn ()
@@ -71,27 +71,27 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
71
71
// Find target board and board properties
72
72
_ , _ , board , boardProperties , _ , err := pm .ResolveFQBN (fqbn )
73
73
if err != nil {
74
- return nil , fmt .Errorf ("Invalid FQBN: %s" , err )
74
+ return nil , fmt .Errorf ("incorrect FQBN: %s" , err )
75
75
}
76
76
77
77
// Load programmer tool
78
78
uploadToolPattern , have := boardProperties .GetOk ("upload.tool" )
79
79
if ! have || uploadToolPattern == "" {
80
- return nil , fmt .Errorf ("The board does not define an 'upload.tool' property. " )
80
+ return nil , fmt .Errorf ("cannot get programmer tool: undefined 'upload.tool' property" )
81
81
}
82
82
83
83
var referencedPlatformRelease * cores.PlatformRelease
84
84
if split := strings .Split (uploadToolPattern , ":" ); len (split ) > 2 {
85
- return nil , fmt .Errorf ("The board defines an invalid 'upload.tool' property: " + uploadToolPattern )
85
+ return nil , fmt .Errorf ("invalid 'upload.tool' property: %s" , uploadToolPattern )
86
86
} else if len (split ) == 2 {
87
87
referencedPackageName := split [0 ]
88
88
uploadToolPattern = split [1 ]
89
89
architecture := board .PlatformRelease .Platform .Architecture
90
90
91
91
if referencedPackage := pm .GetPackages ().Packages [referencedPackageName ]; referencedPackage == nil {
92
- return nil , fmt .Errorf ("The board requires platform '" + referencedPackageName + ":" + architecture + "' that is not installed." )
92
+ return nil , fmt .Errorf ("required platform %s:%s not installed" , referencedPackageName , architecture )
93
93
} else if referencedPlatform := referencedPackage .Platforms [architecture ]; referencedPlatform == nil {
94
- return nil , fmt .Errorf ("The board requires platform '" + referencedPackageName + ":" + architecture + "' that is not installed." )
94
+ return nil , fmt .Errorf ("required platform %s:%s not installed" , referencedPackageName , architecture )
95
95
} else {
96
96
referencedPlatformRelease = pm .GetInstalledPlatformRelease (referencedPlatform )
97
97
}
@@ -153,7 +153,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
153
153
outputTmpFile , ok := uploadProperties .GetOk ("recipe.output.tmp_file" )
154
154
outputTmpFile = uploadProperties .ExpandPropsInString (outputTmpFile )
155
155
if ! ok {
156
- return nil , fmt .Errorf ("The platform does not define the required property 'recipe.output.tmp_file'. " )
156
+ return nil , fmt .Errorf ("property 'recipe.output.tmp_file' not defined " )
157
157
}
158
158
ext := filepath .Ext (outputTmpFile )
159
159
if strings .HasSuffix (importFile , ext ) {
@@ -165,22 +165,22 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
165
165
uploadFile := importPath .Join (importFile + ext )
166
166
if _ , err := uploadFile .Stat (); err != nil {
167
167
if os .IsNotExist (err ) {
168
- return nil , fmt .Errorf ("Compiled sketch not found: " + uploadFile .String ()+ ". Please compile first." , err )
168
+ return nil , fmt .Errorf ("compiled sketch %s not found" , uploadFile .String ())
169
169
} else {
170
- return nil , fmt .Errorf ("Could not open compiled sketch. " , err )
170
+ return nil , fmt .Errorf ("cannot open sketch: %s " , err )
171
171
}
172
172
}
173
173
174
174
// Perform reset via 1200bps touch if requested
175
175
if uploadProperties .GetBoolean ("upload.use_1200bps_touch" ) {
176
176
ports , err := serial .GetPortsList ()
177
177
if err != nil {
178
- return nil , fmt .Errorf ("Can't get serial port list" , err )
178
+ return nil , fmt .Errorf ("cannot get serial port list: %s " , err )
179
179
}
180
180
for _ , p := range ports {
181
181
if p == port {
182
182
if err := touchSerialPortAt1200bps (p ); err != nil {
183
- return nil , fmt .Errorf ("Can't perform reset via 1200bps-touch on serial port " , err )
183
+ return nil , fmt .Errorf ("cannot perform reset: %s " , err )
184
184
}
185
185
break
186
186
}
@@ -197,7 +197,7 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
197
197
actualPort := port // default
198
198
if uploadProperties .GetBoolean ("upload.wait_for_upload_port" ) {
199
199
if p , err := waitForNewSerialPort (); err != nil {
200
- return nil , fmt .Errorf ("Could not detect serial ports" , err )
200
+ return nil , fmt .Errorf ("cannot detect serial ports: %s " , err )
201
201
} else if p == "" {
202
202
formatter .Print ("No new serial port detected." )
203
203
} else {
@@ -223,13 +223,13 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
223
223
cmdLine := uploadProperties .ExpandPropsInString (recipe )
224
224
cmdArgs , err := properties .SplitQuotedString (cmdLine , `"'` , false )
225
225
if err != nil {
226
- return nil , fmt .Errorf ("Invalid recipe in platform." , err )
226
+ return nil , fmt .Errorf ("invalid recipe '%s': %s" , recipe , err )
227
227
}
228
228
229
229
// Run Tool
230
230
cmd , err := executils .Command (cmdArgs )
231
231
if err != nil {
232
- return nil , fmt .Errorf ("Could not execute upload tool. " , err )
232
+ return nil , fmt .Errorf ("cannot execute upload tool: %s " , err )
233
233
}
234
234
235
235
executils .AttachStdoutListener (cmd , executils .PrintToStdout )
@@ -238,11 +238,11 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
238
238
cmd .Stderr = errStream
239
239
240
240
if err := cmd .Start (); err != nil {
241
- return nil , fmt .Errorf ("Could not execute upload tool. " , err )
241
+ return nil , fmt .Errorf ("cannot execute upload tool: %s " , err )
242
242
}
243
243
244
244
if err := cmd .Wait (); err != nil {
245
- return nil , fmt .Errorf ("Error during upload. " , err )
245
+ return nil , fmt .Errorf ("uploading error: %s " , err )
246
246
}
247
247
return & rpc.UploadResp {}, nil
248
248
}
@@ -253,12 +253,12 @@ func touchSerialPortAt1200bps(port string) error {
253
253
// Open port
254
254
p , err := serial .Open (port , & serial.Mode {BaudRate : 1200 })
255
255
if err != nil {
256
- return fmt .Errorf ("open port: %s" , err )
256
+ return fmt .Errorf ("opening port: %s" , err )
257
257
}
258
258
defer p .Close ()
259
259
260
260
if err = p .SetDTR (false ); err != nil {
261
- return fmt .Errorf ("can't set DTR" )
261
+ return fmt .Errorf ("cannot set DTR" )
262
262
}
263
263
return nil
264
264
}
0 commit comments