Skip to content

raea run: console output and the default export's return value never reach the terminal (exit 0), so checkLayout checks always look clean #168

Open

Description

@shinyobjectz

raea run SCRIPT.ts is documented as "what it prints is the answer", but nothing a program logs reaches the terminal:
console.log, console.info, console.warn and console.error all vanish, the default export's return value isn't
printed, and the run exits 0. Reported by an agent through raea bug on raea 0.1.6 (macOS arm64); its workaround was
to smuggle the answer out in a spec's title.

It matters beyond the one report: the 3D guides tell agents to check a layout with raea run check.ts and fix every
error checkLayout prints (sdk/guides/craft/bevy/rooms.md, scenes.md, prompts.md). checkLayout returns its
findings, and a check script logs them, so every such check prints nothing and exits 0, which reads as a clean layout.

Reproduce

// fn.ts
export default function () {
  console.log("log inside default")
  return { answer: 42 }
}
raea run fn.ts   # prints nothing, exit 0

The same on the 0.1.6 release (macOS arm64) and a build of main from 11-15, for four scripts:

Script stdout stderr exit
top-level console.log and console.error empty empty 0
default export logs and returns { answer: 42 } empty empty 0
async default export logs after an await and returns a string empty empty 0
default export throws new Error("boom from the script") error: throws_default@bundle.js:3:18 / @bundle.js:6:84 empty 1

The thrown error's message is missing from its report too: only the stack's frames print.

Why

  • The console goes to Bevy's log, which raea run never sets up. The prelude routes console.* to __raea_log
    (sdk/react/js/src/prelude.js), which runtime/react/src/thread.rs (fn log) hands to info!/warn!/error!.
    run_bundle (runtime/export/src/run.rs) builds its app from MinimalPlugins and the React plugin, with no
    LogPlugin, so no subscriber exists and every line is dropped.
  • Only the native print call reaches stdout (runtime/calls/src/lib.rs, "print", echoed while ECHO is
    set). Nothing in a plain script calls it; the run's own entry uses it only for the error.
  • The return value is never looked at. bundle_script's entry (runtime/bundle/src/fresh.rs) calls and awaits
    the default export, then sends done without printing what came back.
  • The error loses its message. The entry prints e.stack; on this engine a stack is only the frames
    (fn@file:line:col), with no Error: message line first.

Fix

  1. In bundle_script's entry, before the module runs, point console.log/info/debug at print (stdout) and
    warn/error at stderr, formatting values the way Node does: strings as they are, everything else through
    JSON.stringify (with a fallback for cycles) or its stack.
  2. Print the default export's value when it isn't undefined: a string as it is, anything else as JSON.
  3. Report a throw as String(e) followed by its stack, on stderr.
  4. A test in the CLI's tests that runs the four scripts above and checks stdout, stderr and the exit code, plus a room
    check that has an overlap and must print its error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions