mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix docker logs error handling
Previously, `docker logs` (and by extension, `docker service logs`) had an error in the way they returned errors that occurred after a stream had already been started. Specifically, the errors were added verbatim to the HTTP response, which caused StdCopy to fail with an esoteric error. This change updates StdCopy to accept errors from the source stream and then return those errors when copying to the destination stream. Signed-off-by: Drew Erny <drew.erny@docker.com>
This commit is contained in:
parent
fddab1444f
commit
f19b0d72d1
4 changed files with 54 additions and 5 deletions
|
|
@ -246,6 +246,35 @@ func TestStdCopyDetectsNotFullyWrittenFrames(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestStdCopyReturnsErrorFromSystem tests that StdCopy correctly returns an
|
||||
// error, when that error is muxed into the Systemerr stream.
|
||||
func TestStdCopyReturnsErrorFromSystem(t *testing.T) {
|
||||
// write in the basic messages, just so there's some fluff in there
|
||||
stdOutBytes := []byte(strings.Repeat("o", startingBufLen))
|
||||
stdErrBytes := []byte(strings.Repeat("e", startingBufLen))
|
||||
buffer, err := getSrcBuffer(stdOutBytes, stdErrBytes)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// add in an error message on the Systemerr stream
|
||||
systemErrBytes := []byte(strings.Repeat("S", startingBufLen))
|
||||
systemWriter := NewStdWriter(buffer, Systemerr)
|
||||
_, err = systemWriter.Write(systemErrBytes)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// now copy and demux. we should expect an error containing the string we
|
||||
// wrote out
|
||||
_, err = StdCopy(ioutil.Discard, ioutil.Discard, buffer)
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got none")
|
||||
}
|
||||
if !strings.Contains(err.Error(), string(systemErrBytes)) {
|
||||
t.Fatal("expected error to contain message")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWrite(b *testing.B) {
|
||||
w := NewStdWriter(ioutil.Discard, Stdout)
|
||||
data := []byte("Test line for testing stdwriter performance\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue