From 999490fae4e9a549fcb144791cee4847e12c907f Mon Sep 17 00:00:00 2001 From: Alex Lai <74868436+Alx-Lai@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:42:52 +0800 Subject: [PATCH] book.js: early return if response error (#2520) It used to have a ugly error message shows that "Playground Communication: Cannot read properties of undefined (reading 'trim')", which is due to the fact that the response lacks stdout attr. Issue: #2477 Signed-off-by: Alx-Lai --- theme/book.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/theme/book.js b/theme/book.js index 4b07867a..a1f23731 100644 --- a/theme/book.js +++ b/theme/book.js @@ -171,6 +171,13 @@ function playground_text(playground, hidden = true) { "latency": (endTime - startTime) / 1000, }); + if (response.error != null && response.error != '') { + // output the error if there's any. e.g. timeout + result_block.innerText = response.error; + result_block.classList.remove("result-no-output"); + return; + } + if (response.stdout.trim() === '') { result_block.innerText = "No output"; result_block.classList.add("result-no-output");