taskrunner
taskrunner copied to clipboard
go prefixedwriter: fix short write error case
In certain cases, formatting as JSON actually reduces the number of bytes.
This leads to the bufio.Writer that wraps this returning short write
error
because the number of bytes returned is less than expected.
We just want to return the original number of bytes, since we know that we are doing some string manipulation and we are OK with that.
See: https://pkg.go.dev/io#Writer
Write writes len(p) bytes from p to the underlying data stream. It returns the
number of bytes written from p (0 <= n <= len(p)) and any error encountered
that caused the write to stop early. Write must return a non-nil error if it
returns n < len(p).
how did I test this?
I noticed that sometimes log lines would get lost. with some investigation, i realized that if taskrunner invokes
x := 1
fmt.Println(x)
fmt.Println("should get here")
"should get here" would not be reached because we do the special json formatting which somehow truncates the number of bytes, and we were getting this short write
error. This was not apparent because we swallow a lot of Write()
errors and such, but I don't want to blow up this PR scope with fixing + testing all of those.
which lead me down to this investigation path.
after this fix, the log lines get printed properly.
i think technically we shouldn't be modifying p, but that seems like a much larger design decision, so I would like to patch this for now
Example before/after? Or at a minimum a "how did I test this"?
@er9781 Added a "how did I test this" section!