Skip to content

Commit

Permalink
Change RecordError to WriteStdErrOut and take both as input, write bo…
Browse files Browse the repository at this point in the history
…th to stdout/stderr and record stderr.
  • Loading branch information
DonggeLiu committed Oct 3, 2023
1 parent 2ba751d commit 6f3f6e4
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions infra/base-images/base-builder/jcc/jcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ func AppendStringToFile(filepath, new_content string) error {
return err
}

func RecordError(errstr string) {
// Prints |errstr| to stderr, and saves it to err log.
func WriteStdErrOut(outstr string, errstr string) {
// Prints |outstr| to stdout, prints |errstr| to stderr, and saves |errstr| to err.log.
fmt.Print(outstr)
fmt.Fprint(os.Stderr, errstr)
AppendStringToFile("/out/err.log", errstr)
}
Expand Down Expand Up @@ -385,8 +386,7 @@ func main() {
}
retcode, out, errstr := Compile(bin, newArgs)
if retcode == 0 {
fmt.Print(out)
RecordError(errstr)
WriteStdErrOut(out, errstr)
os.Exit(0)
}

Expand All @@ -407,24 +407,20 @@ func main() {
// Nothing else we can do. Just write the error and exit.
// Just print the original error for debugging purposes and
// to make build systems happy.
fmt.Print(out)
RecordError(errstr)
WriteStdErrOut(out, errstr)
os.Exit(retcode)
}
fixret, fixout, fixerr := TryFixCCompilation(newArgs)
if fixret != 0 {
// We failed, write stdout and stderr from the first failure and
// from fix failures so we can know what the code did wrong and
// how to improve jcc to fix more issues.
fmt.Print(out)
RecordError(errstr)
WriteStdErrOut(out, errstr)
fmt.Println("\nFix failure")
fmt.Print(fixout)
// Print error back to stderr so tooling that relies on this can proceed
RecordError(fixerr)
WriteStdErrOut(fixout, fixerr)
os.Exit(retcode)
}
// The fix suceeded, write its out and err.
fmt.Print(fixout)
RecordError(fixerr)
WriteStdErrOut(fixout, fixerr)
}

0 comments on commit 6f3f6e4

Please sign in to comment.