Skip to content

Commit f69c398

Browse files
committed
Fix: Playground errors when serializing logs
1 parent c341935 commit f69c398

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

packages/playground/src/sidebar/runtime.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,23 @@ function rewireLoggingToElement(
234234
}
235235

236236
function produceOutput(args: any[]) {
237-
let result: string = args.reduce((output: any, arg: any, index) => {
238-
const textRep = objectToText(arg)
239-
const showComma = index !== args.length - 1
240-
const comma = showComma ? "<span class='comma'>, </span>" : ""
241-
return output + textRep + comma + " "
242-
}, "")
243-
244-
Object.keys(replacers).forEach(k => {
245-
result = result.replace(new RegExp((replacers as any)[k], "g"), k)
246-
})
247-
248-
return result
237+
try {
238+
let result: string = args.reduce((output: any, arg: any, index) => {
239+
const textRep = objectToText(arg)
240+
const showComma = index !== args.length - 1
241+
const comma = showComma ? "<span class='comma'>, </span>" : ""
242+
return output + textRep + comma + " "
243+
}, "")
244+
245+
Object.keys(replacers).forEach(k => {
246+
result = result.replace(new RegExp((replacers as any)[k], "g"), k)
247+
})
248+
249+
return result
250+
} catch (error) {
251+
console.warn(i("play_run_log_fail"), error)
252+
return i("play_run_log_fail")
253+
}
249254
}
250255
}
251256

packages/typescriptlang-org/src/copy/en/playground.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const playCopy = {
5555
play_run_js: "Executed JavaScript",
5656
play_run_ts: "Executed transpiled TypeScript",
5757
play_run_js_fail: "Executed JavaScript Failed:",
58+
play_run_log_fail: "Failed to serialize log",
5859
play_default_code_sample: `// Welcome to the TypeScript Playground, this is a website
5960
// which gives you a chance to write, share and learn TypeScript.
6061

0 commit comments

Comments
 (0)