motoko-base icon indicating copy to clipboard operation
motoko-base copied to clipboard

Document `debug` blocks, and how to use them.

Open matthewhammer opened this issue 2 years ago • 4 comments

Document how to use debug blocks.

Debug blocks

A debug block denotes code is only present in development mode, and elided in production.

debug { printfs here }

Compilation modes

from moc --help:

  • --release ignore debug expressions in source
  • --debug respect debug expressions in source (the default)

matthewhammer avatar Jul 14 '22 15:07 matthewhammer

🎉

q-uint avatar Jul 14 '22 15:07 q-uint

@matthewhammer

There is a quick reference on how I have used it: https://github.com/internet-computer/debug-block.mo

(As far as I know) there is no direct support in DFX to pass arguments to moc (e.g. --debug or --release).

q-uint avatar Jul 27 '22 15:07 q-uint

I think you can have a motoko build method in dfx.json and have an attribute "args" with "--debug" below it. @di-wu

ggreif avatar Jul 27 '22 22:07 ggreif

Thanks @ggreif~ This makes it much simpler to set up!

dfx.json

{
    "canisters": {
        "prod": {
            "type": "motoko",
            "main":  "src/main.mo",
            "args": "--release"
        },
        "dev": {
            "type": "motoko",
            "main":  "src/main.mo"
        }
    }
}

q-uint avatar Jul 28 '22 07:07 q-uint