Debugging
There are some tricks you can use to help you find and fix errors in your Easel programs.
Console debugging
The browser console is a place where you can see messages from the browser and any code it is running.
You can open your browser console by pressing F12
and selecting the Console
tab.
You can use functions like ConsoleLog to print messages to the browser console.
This can help you trace the flow of your program and see the values of variables at different points.
pub fn Example() {
ConsoleLog("Hello, world!")
let a = 2 + 3;
ConsoleLog("a is now: " + a)
}
How to open your browser console:
- Google Chrome/Microsoft Edge: From the menu, select
More tools
, thenDeveloper tools
. - Firefox: From the menu, select
Web Developer
, thenWeb Console
. - Safari: From the menu, select
Develop
, thenShow JavaScript Console
.
Assert statements
You can use an Assert
statement to verify that a condition is true.
If the condition is false, the program will stop and display an error message.
The error message will include a stack trace,
which is a list of the functions that were called to get to the point where the error occurred,
including their filename and line number.
This can help you find the source of the error quickly.
Assert(condition, message?)
Asset takes two parameters:
condition
: The condition to check. Should return a Truthy value when everything is working as expected.message
: The error message to display if the assertion fails. This parameter is optional. This expression is only executed if the condition is false, so you can write expensive operations here without worrying about performance. You may want to include enough information to help debug the problem.
pub fn Example() {
let a = 2 + 3;
Assert(a == 5, "'a' should be 5!")
Assert(a == 5) // error message is optional
}
While Assert
looks like a normal function, it is not, it is a compiler intrinsic.
That is why it is able to conditionally execute the second parameter.
That is also why you won't find it in the function reference.