fluffos/testsuite/lpcshell/errors.lpcs
gesslar 17280e6a5c lpcshell: report runtime errors instead of a bogus syntax error
A statement that parsed but then error()ed printed only

    /lpcshell#1:6:1: error: syntax error, unexpected '}'

and never the real message. Two separate faults combined to produce it.

RunAttempt() returned a bare bool, so Eval() could not tell "did not
compile" from "compiled, ran, and error()ed" and retried the latter in
statement form. That retry is wrong twice over: it re-executes whatever
side effects the expression already had, and a bare expression has no
terminating ';' as a statement, so it dies on the generated closing brace
-- and that bogus diagnostic is the only one the user sees.

The real message was also unrecoverable. error() hands the text to the
mudlib's error_handler apply and then throws the generic "error handler
error" (simulate.cc), so against a mudlib that routes errors anywhere
other than stdout there was nothing left to report -- lpcshell failed
mutely apart from the misleading brace error.

So: RunAttempt() now returns kOk/kCompileError/kRuntimeError, and a trial
that reached runtime is never retried. Each body is wrapped in an
LPC-level catch() so the error arrives as a value with its real text,
independent of what the mudlib does with errors. The user's text is
emitted on its own line in the generated source, so diagnostics quote
what was actually typed at the right column instead of the wrapper --
which also stops a trailing // comment from swallowing the wrapper's
closing tokens, and lets the statement form terminate a sequence like
`write("a"); write("b")` that the user simply left unterminated.

    -  ]SIDE  ]SIDE           side effects twice, real error never shown
    +  ]SIDE  error: bang     once, reported

Tested via two ctest entries driving the binary in script mode
(`ctest -L lpcshell`); the LPC testsuite cannot reach this code, which
is C++. Both fail against the unpatched binary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVj9t8GPkUiZYLJUyiRehD
2026-07-17 11:58:32 -07:00

6 lines
79 B
Text

error("boom")
"AFTER_ERROR"
int n;
n = 0;
(n = n + 1, error("bang"));
"n=" + n