Re:Go 2 Draft Designs
by ianlancetaylor on Tuesday August 28, 2018 @04:10PM
(#17862425)
Yes, the various fmt.Print functions only return an error if Write on the underlying Writer returns an error.
Here you go: https://play.golang.org/p/0vGdejrjm5H
To reproduce the key lines here:
os.Stdout.Close()
_, err := fmt.Println("foo")
You can also close stdout from outside the program, use ptrace to cause the write call to fail, or a number of other things.
In fact, the only _print function I could get to fail was Fprintf by sending an already closed file. I suppose if it was somehow not allowed to write to stdout the other functions might fail. But I'm not sure.