mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
raea run's program said nothing: its console went to the log, and raea run's headless App has no log, so every console line was dropped. The default export's return value was dropped too. A throw printed its stack alone, which on JavaScriptCore is only the frames, so the message was missing. - runtime/calls: CONSOLE. While it's on (and ECHO), a script's console goes to the terminal as node's does: log and info to stdout, warn and error to stderr (raea-runtime-react's __raea_log). print takes err for a line meant for stderr. - raea-runtime-export: run_bundle_to_terminal turns it on for raea run, raea test and raea blender run. raea check's asks and a spec's read keep run_bundle, whose stdout is their answer. - raea-runtime-bundle: bundle_script's entry (script_entry.ts) prints what the default export returns, a string as it is and anything else as indented JSON. A throw prints as error: Name: message, then the stack, on stderr, exit 1. Checked with the issue's cases on this build: console lines before and after an await, both streams, a returned object and a returned string, a throw (exit 1, message and stack on stderr), a script with no default export. raea test's output is unchanged (random-colors.test.ts, 9 pass). The manual's raea run page says all of it, with an example.
7 lines
1.1 KiB
TypeScript
7 lines
1.1 KiB
TypeScript
// bundle_script's entry (fresh.rs): the default export called and awaited; what it returns printed (a string as it
|
|
// is, anything else as JSON), and a throw printed as its name and message, then its stack, on stderr. A script's answer
|
|
// was dropped and a throw printed its stack alone, which on JavaScriptCore is only the frames, without the message (#168).
|
|
const show = (v: any): string => { if (typeof v === "string") return v; try { return JSON.stringify(v, null, 2) ?? String(v); } catch { return String(v); } };
|
|
const said = (e: any): string => { const head = e && typeof e === "object" && "message" in e ? (e.name || "Error") + ": " + e.message : String(e); const stack = e && e.stack ? String(e.stack) : ""; return stack.startsWith(head) ? stack : stack ? head + "\n" + stack : head; };
|
|
Promise.resolve().then(() => (typeof (M as any).default === "function" ? (M as any).default() : undefined)).then((v: any) => { if (v !== undefined) call("print", JSON.stringify({ text: show(v) })); call("done", JSON.stringify({ code: 0 })); }, (e: any) => { call("print", JSON.stringify({ text: "error: " + said(e), err: true })); call("done", JSON.stringify({ code: 1 })); });
|