Fixed bug with multiline streams

This commit is contained in:
Kasra Bigdeli
2020-01-02 16:50:10 -05:00
parent 26a11a83e4
commit de54d34f3a
+19 -22
View File
@@ -23,30 +23,27 @@ function safeParseChunk(
error?: any
errorDetail?: any
}[] {
chunk = `${chunk}`.trim()
try {
return [JSON.parse(chunk)]
// See https://github.com/caprover/caprover/issues/570
// This appears to be bug either in Docker or dockerone:
// Sometimes chunk appears as two JSON objects, like
// ```
// {"stream":"something......"}
// {"stream":"another line of things"}
// ```
const chunks = chunk.split('\n')
const returnVal = [] as any[]
chunks.forEach(chk => {
returnVal.push(JSON.parse(chk))
})
return returnVal
} catch (ignore) {
try {
// See https://github.com/caprover/caprover/issues/570
// This appears to be bug either in Docker or dockerone:
// Sometimes chunk appears as two JSON objects, like
// ```
// {"stream":"something......"}
// {"stream":"another line of things"}
// ```
const chunks = chunk.split('\n')
const returnVal = [] as any[]
chunks.forEach(chk => {
returnVal.push(JSON.parse(chk))
})
return returnVal
} catch (ignore) {
return [
{
stream: 'Cannot parse ' + chunk,
},
]
}
return [
{
stream: 'Cannot parse ' + chunk,
},
]
}
}