File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -417,3 +417,7 @@ func (r *compileResult) String() string {
417
417
}
418
418
return strings .TrimRight (res , fmt .Sprintln ())
419
419
}
420
+
421
+ func (r * compileResult ) ErrorString () string {
422
+ return r .Error
423
+ }
Original file line number Diff line number Diff line change @@ -102,6 +102,13 @@ type Result interface {
102
102
Data () interface {}
103
103
}
104
104
105
+ // ErrorResult is a result embedding also an error. In case of textual output
106
+ // the error will be printed on stderr.
107
+ type ErrorResult interface {
108
+ Result
109
+ ErrorString () string
110
+ }
111
+
105
112
var tr = i18n .Tr
106
113
107
114
// SetOut can be used to change the out writer at runtime
@@ -169,7 +176,7 @@ func FatalError(err error, exitCode ExitCode) {
169
176
}
170
177
171
178
// FatalResult outputs the result and exits with status exitCode.
172
- func FatalResult (res Result , exitCode ExitCode ) {
179
+ func FatalResult (res ErrorResult , exitCode ExitCode ) {
173
180
PrintResult (res )
174
181
os .Exit (int (exitCode ))
175
182
}
@@ -229,6 +236,7 @@ func augment(data interface{}) interface{} {
229
236
// structure.
230
237
func PrintResult (res Result ) {
231
238
var data string
239
+ var dataErr string
232
240
switch format {
233
241
case JSON :
234
242
d , err := json .MarshalIndent (augment (res .Data ()), "" , " " )
@@ -250,10 +258,16 @@ func PrintResult(res Result) {
250
258
data = string (d )
251
259
case Text :
252
260
data = res .String ()
261
+ if resErr , ok := res .(ErrorResult ); ok {
262
+ dataErr = resErr .ErrorString ()
263
+ }
253
264
default :
254
265
panic ("unknown output format" )
255
266
}
256
267
if data != "" {
257
268
fmt .Fprintln (stdOut , data )
258
269
}
270
+ if dataErr != "" {
271
+ fmt .Fprintln (stdErr , dataErr )
272
+ }
259
273
}
You can’t perform that action at this time.
0 commit comments