mirror of
https://github.com/caprover/caprover
synced 2026-09-25 08:05:35 +00:00
Fixed bug with multiline streams
This commit is contained in:
+19
-22
@@ -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,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user