Skip to content

Commit 19e325c

Browse files
Print errors to stderr
Previously, errors would be dumped to stdout, which of course is not ideal. Moreover, when the Arduino IDE runs arduino-builder --dump-prefs, the errors would end up intermixed with the preferences, or be completely ignored by the IDE when a fatal error occured. Printing errors to stderr causes them to be printed properly by the IDE. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent 91b2188 commit 19e325c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

main.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func main() {
119119
dumpPrefs := *dumpPrefsFlag
120120

121121
if compile && dumpPrefs {
122-
fmt.Println("You can either specify --compile or --dump-prefs, not both")
122+
fmt.Fprintln(os.Stderr, "You can either specify --compile or --dump-prefs, not both")
123123
defer os.Exit(1)
124124
return
125125
}
@@ -138,7 +138,7 @@ func main() {
138138
}
139139

140140
if len(hardware) == 0 {
141-
fmt.Println("Parameter 'hardware' is mandatory")
141+
fmt.Fprintln(os.Stderr, "Parameter 'hardware' is mandatory")
142142
flag.Usage()
143143
defer os.Exit(1)
144144
return
@@ -153,7 +153,7 @@ func main() {
153153
}
154154

155155
if len(tools) == 0 {
156-
fmt.Println("Parameter 'tools' is mandatory")
156+
fmt.Fprintln(os.Stderr, "Parameter 'tools' is mandatory")
157157
flag.Usage()
158158
defer os.Exit(1)
159159
return
@@ -184,7 +184,7 @@ func main() {
184184
}
185185

186186
if fqbn == "" {
187-
fmt.Println("Parameter 'fqbn' is mandatory")
187+
fmt.Fprintln(os.Stderr, "Parameter 'fqbn' is mandatory")
188188
flag.Usage()
189189
defer os.Exit(1)
190190
return
@@ -201,7 +201,7 @@ func main() {
201201
if buildPath != "" {
202202
_, err := os.Stat(buildPath)
203203
if err != nil {
204-
fmt.Println(err)
204+
fmt.Fprintln(os.Stderr, err)
205205
defer os.Exit(1)
206206
return
207207
}
@@ -216,7 +216,7 @@ func main() {
216216
context[constants.CTX_BUILD_PATH] = buildPath
217217

218218
if compile && flag.NArg() == 0 {
219-
fmt.Println("Last parameter must be the sketch to compile")
219+
fmt.Fprintln(os.Stderr, "Last parameter must be the sketch to compile")
220220
flag.Usage()
221221
defer os.Exit(1)
222222
return
@@ -264,10 +264,10 @@ func main() {
264264
if err != nil {
265265
err = utils.WrapError(err)
266266

267-
fmt.Println(err)
267+
fmt.Fprintln(os.Stderr, err)
268268

269269
if utils.DebugLevel(context) >= 10 {
270-
fmt.Println(err.(*errors.Error).ErrorStack())
270+
fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack())
271271
}
272272

273273
exitCode = toExitCode(err)
@@ -299,5 +299,5 @@ func toSliceOfUnquoted(value slice) ([]string, error) {
299299

300300
func printCompleteError(err error) {
301301
err = utils.WrapError(err)
302-
fmt.Println(err.(*errors.Error).ErrorStack())
302+
fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack())
303303
}

0 commit comments

Comments
 (0)