Skip to content

Commit

Permalink
fix: improve DEBUG:vike-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jun 27, 2024
1 parent 350c23e commit ef0eb3d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions vike/node/runtime/html/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async function createStreamWrapper({
assert(writableOriginal)
writableOriginal.write(chunk)
if (debug.isActivated) {
debug('data written (Node.js Writable)', String(chunk))
debug('data written (Node.js Writable)', getChunkAsString(chunk))
}
}
// For libraries such as https://www.npmjs.com/package/compression
Expand Down Expand Up @@ -565,7 +565,7 @@ async function createStreamWrapper({
assert(writerOriginal)
writerOriginal.write(encodeForWebStream(chunk))
if (debug.isActivated) {
debug('data written (Web Writable)', String(chunk))
debug('data written (Web Writable)', getChunkAsString(chunk))
}
}
// Web Streams have compression built-in
Expand Down Expand Up @@ -665,11 +665,11 @@ async function createStreamWrapper({
) {
controllerProxy.enqueue(encodeForWebStream(chunk) as any)
if (debug.isActivated) {
debug('data written (Web Readable)', String(chunk))
debug('data written (Web Readable)', getChunkAsString(chunk))
}
} else {
if (debug.isActivated) {
debug('data emitted but not written (Web Readable)', String(chunk))
debug('data emitted but not written (Web Readable)', getChunkAsString(chunk))
}
}
}
Expand All @@ -696,7 +696,7 @@ async function createStreamWrapper({
const writeChunk = (chunk: unknown) => {
readableProxy.push(chunk)
if (debug.isActivated) {
debug('data written (Node.js Readable)', String(chunk))
debug('data written (Node.js Readable)', getChunkAsString(chunk))
}
}
// Readables don't have the notion of flushing
Expand Down Expand Up @@ -953,3 +953,11 @@ function inferStreamName(stream: StreamProviderNormalized) {
}
assert(false)
}

function getChunkAsString(chunk: unknown): string {
try {
return new TextDecoder().decode(chunk as any)
} catch (err) {
return String(chunk)
}
}

0 comments on commit ef0eb3d

Please sign in to comment.