haumea-lang / haumea-rs

Haumea is an experimental language designed to be simple and easy to learn and program in.
MIT License
7 stars 2 forks source link

Add better error handling #3

Open BookOwl opened 7 years ago

BookOwl commented 7 years ago

Currently, there is very little error handling. Syntax errors ARE handled, but they don't give very user friendly error messages. Even worse, there is no checking for semantic errors, so the C compiler has to handle them. Since this language is designed to be easy for beginners, this is a problem!

bates64 commented 7 years ago

image

:clap: :100:

bates64 commented 7 years ago

I'd say, if you can, make errors like those the Elm compiler creates - actually helpful ones e.g.

The right argument of (+) is causing a type mismatch.

3|   1 + "ohai"
         ^^^^^^
(+) is expecting the right argument to be a:

    number

But the right argument is:

    String

Hint: To append strings in Elm, you need to use the (++) operator, not (+).
<http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#++>
bates64 commented 7 years ago

Also providing a) compiler warnings and b) line/col numbers is important. It'll be worth creating a function that panics for us 🙂

joker314 commented 7 years ago

Yes, and if possible, try/catch clauses try to <STATEMENT>

e.g.

try to do
display("Hello" / 7) /* This is a type error */
else with VARNAME do 
display("Uh oh! An error occurred. Here are the details: " + VARNAME)
end
BookOwl commented 7 years ago

Right now I'm going to try and make error messages include the line/column that the error message happened.

TheMonsterFromTheDeep commented 7 years ago

@joker314 what would that do? I don't think throwing a type error at runtime would make much sense, because the compiler should simply refuse to compile if there is an error like that.

Although I think the types of errors handled in C++ by exceptions (allocation failures and stuff) could be handled through exceptions in Haumea as well

BookOwl commented 7 years ago

Right now I'm going to try and make error messages include the line/column that the error message happened.

OK, so this is a bit harder than I thought, since it involves changing the Token enum members to include the line/column, which means that I'll have to change quite a bit of code. 😢

BookOwl commented 7 years ago

f57045f adds line:column info to the error messages! :D