Skip to content

Add good runtime errors#58

Merged
cyteon merged 5 commits intomainfrom
good-errors
Mar 17, 2026
Merged

Add good runtime errors#58
cyteon merged 5 commits intomainfrom
good-errors

Conversation

@cyteon
Copy link
Owner

@cyteon cyteon commented Mar 17, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances Modu runtime error reporting by attaching source spans to emitted bytecode instructions and rendering errors as Ariadne reports (optionally with “did you mean” help), then updates CLI/wasm frontends to print the richer error output.

Changes:

  • Track SimpleSpan per instruction in Chunk, and plumb spans through the compiler emit path.
  • Use spans at runtime to format VM errors as Ariadne reports (including help suggestions for “closest match” cases).
  • Adjust CLI/wasm error printing and extend debug disassembly output to include spans.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
modu-wasm/src/lib.rs Prints the new formatted runtime error output directly.
lang/test Adds a stray file containing invalid Modu code (likely a manual repro).
lang/src/vm/vm.rs Adds span-aware runtime error formatting via Ariadne and updates many runtime error sites to use it.
lang/src/vm/chunk.rs Stores spans alongside instructions and updates emit to accept a span.
lang/src/compiler/compiler.rs Passes AST spans into all bytecode emission sites; ensures if leaves a stack value when no else.
lang/src/cli/run.rs Prints formatted runtime errors and shows spans in instruction debug output.
lang/src/cli/repl.rs Prints formatted runtime errors in the REPL loop.
lang/examples/benchmark.modu Adds a benchmark example program.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +904 to +908
fn runtime_error_with_help(&self, msg: String, help: String, span: SimpleSpan) -> String {
let src = std::fs::read_to_string(&self.source_path).unwrap_or_default();
let filename = self.source_path.to_string_lossy().to_string();

let mut buf: Vec<u8> = Vec::new();
Comment on lines +886 to +889
fn runtime_error(&self, msg: String, span: SimpleSpan) -> String {
let src = std::fs::read_to_string(&self.source_path).unwrap_or_default();
let filename = self.source_path.to_string_lossy().to_string();

return Err(format!("undefined property '{}' on object.\nDid you maybe mean: '{}'?", name, closest.green()));
return Err(self.runtime_error_with_help(
format!("undefined property '{}' on object", name),
format!("did you maybe mean: '{}'?", closest.green()),
@@ -0,0 +1 @@
"".replac(); No newline at end of file
@cyteon cyteon merged commit 34a290b into main Mar 17, 2026
6 checks passed
@cyteon cyteon deleted the good-errors branch March 18, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants