diff --git a/src/docker/DockerApi.ts b/src/docker/DockerApi.ts index 3de9646..ea508fe 100644 --- a/src/docker/DockerApi.ts +++ b/src/docker/DockerApi.ts @@ -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, + }, + ] } }