File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -411,3 +411,7 @@ func (r *compileResult) String() string {
411411 }
412412 return strings .TrimRight (res , fmt .Sprintln ())
413413}
414+
415+ func (r * compileResult ) ErrorString () string {
416+ return r .Error
417+ }
Original file line number Diff line number Diff line change @@ -102,6 +102,13 @@ type Result interface {
102102 Data () interface {}
103103}
104104
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+
105112var tr = i18n .Tr
106113
107114// SetOut can be used to change the out writer at runtime
@@ -169,7 +176,7 @@ func FatalError(err error, exitCode ExitCode) {
169176}
170177
171178// FatalResult outputs the result and exits with status exitCode.
172- func FatalResult (res Result , exitCode ExitCode ) {
179+ func FatalResult (res ErrorResult , exitCode ExitCode ) {
173180 PrintResult (res )
174181 os .Exit (int (exitCode ))
175182}
@@ -229,6 +236,7 @@ func augment(data interface{}) interface{} {
229236// structure.
230237func PrintResult (res Result ) {
231238 var data string
239+ var dataErr string
232240 switch format {
233241 case JSON :
234242 d , err := json .MarshalIndent (augment (res .Data ()), "" , " " )
@@ -250,10 +258,16 @@ func PrintResult(res Result) {
250258 data = string (d )
251259 case Text :
252260 data = res .String ()
261+ if resErr , ok := res .(ErrorResult ); ok {
262+ dataErr = resErr .ErrorString ()
263+ }
253264 default :
254265 panic ("unknown output format" )
255266 }
256267 if data != "" {
257268 fmt .Fprintln (stdOut , data )
258269 }
270+ if dataErr != "" {
271+ fmt .Fprintln (stdErr , dataErr )
272+ }
259273}
You can’t perform that action at this time.
0 commit comments