| slug | /debugging |
|---|
By default, the compiler optimizes your program as much as possible, and leaves out anything that isn't needed for it to run correctly, such as error messages.
When you compile in debug mode, with rue build --debug:
debugstatements are included in the program.raisestatements include their message, and the location they occurred at.- Failed
assertstatements raise a message with their location, such as"assertion failed at main.rue:2:5". - Some optimizations are disabled, so the output more closely matches the structure of your code.
Tests are always compiled in debug mode.
:::warning
Debug builds should only be used for development. They are larger and more expensive to run, have a different puzzle hash than the normal build, and debug statements use an operator that isn't part of standard CLVM. Always deploy puzzles compiled without --debug.
:::
You can use debug statements to print values to the console while a program runs:
fn main(value: Int) -> Int {
debug value;
value * 2
}
The value can be anything, and is printed as an untyped CLVM value, along with the location of the statement.
If you compile this with rue build, it will be omitted from the compiled program (since printing isn't supported in CLVM natively). However, if you compile this with rue build --debug, special debug symbols will be included that will print the value at runtime.
This modified version of CLVM can be executed with the rue debug command, with rue test, or with the Wallet SDK simulator. For example:
$ rue debug "$(rue build --debug)" "(10)"
main.rue:2:5: 10
20:::tip
Since debug statements shouldn't be left in your code once you're done with them, you can enable the debug_statement lint to report any that remain.
:::
The rue debug command runs any CLVM program against a solution, and prints the result. This is useful for checking how a compiled puzzle behaves with different solutions, without having to write a test:
$ rue build
(* 2 (q . 2))
$ rue debug "(* 2 (q . 2))" "(10)"
20See Command Line for the available options.