Skip to content

Improve error messages in the W++ Interpreter #3

@sinisterMage

Description

@sinisterMage

📝 Summary

W++ is quirky and chaotic by design — but error messages shouldn’t be. Right now, if you write incorrect W++ code (like referencing an undefined variable or calling a function wrong), the interpreter throws raw C# exceptions, like:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

This is unhelpful for users who don’t know or care that the interpreter is written in C#. Let’s fix that!


🎯 What needs to be done

  1. Identify common exception sources in Interpreter.cs and related files (e.g., undefined variable access, wrong number of function args, invalid member access).

  2. Wrap those sections with more user-friendly error handling, like:

if (!variables.ContainsKey(name))
{
    throw new WppRuntimeException($"Variable '{name}' is not defined.");
}
  1. (Optional) Create a custom exception class like WppRuntimeException that pretty-prints errors in a consistent and readable way (e.g., with line number if available).

  2. Make sure the CLI catches and displays these nicely.


💡 Examples of improvements

Before After
KeyNotFoundException W++ Error: Variable 'foo' is not defined.
ArgumentOutOfRangeException W++ Error: Index 10 out of range for list of length 3.
NullReferenceException W++ Error: Attempted to access a property on null.

✅ Why this issue is good for beginners

  • It’s isolated and doesn't require deep knowledge of the interpreter internals.

  • You’ll learn how the W++ interpreter evaluates code.

  • You’ll improve the experience of every single user. ❤️


🧪 How to test it

You can write a .wpp file that does something wrong, like:

print(unknownVar)

Then run:

ingot run hello.wpp

Before your fix, it’ll throw a nasty C# stack trace. After your fix, it should show something friendly like:

W++ Error: Variable 'unknownVar' is not defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededinterpreterissue releated to the W++ interpreter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions