This is not something that's stopping me in my tracks. Just something that feels like I'm holding it wrong.
How do you debug a roc function when it doesn't work as expected?
My usual go-to is calling the function from a repl, but I can't figure out how to import roc files from a repl.
The expect
keyword is cool. But it doesn't tell me what the output actually was - just that it's wrong. (Not so useful)
The dbg
keyword seems to be completely broken? It panics every time, so maybe it's just not implemented yet?
The only thing I can think of is turning everything into Task
, and then doing the Num.toStr |> Stdout.line |> Task.await
dance everytime.
...but it's a lot of cumbersome boilerplate and type-faffery just to get my eyes onto the result of a function call.
Am I doing it wrong?
How do I get to see the result of a function I wrote?
Ideally I'd like to just call my roc functions from a repl.
Is there something like python -i
in Roc? Is it possible to import Roc code to the repl in any way?
Importing roc files form the repl is not yet supported.
dbg
should work a whole lot better now with today's nightly and basic-cli 0.7.0
Hmm.. I'm on the very latest commit on roc master
rn- and the compiler just panicks and says "this is definitely a compiler bug" whenever there is a dbg
statement anywere. No matter where.
I'll try updating to basic-cli 0.7.0, and see if that makes a difference.
But I thought dbg
was a language-specific thing, and not something implemented by the platform?
we recently changed that - basically now the platform is in charge of specifying where dbg
gets written to - so, for example, if you're running a WebAssembly platform in the browser, it might be implemented using console.log
, or in a VS Code extension it might show up in a developer console
but more relevantly here, the new way we're doing things fixes a bunch of bugs with the old implementation :big_smile:
I have noticed that the "this is definitely a compiler bug" message gets logged a lot, for things that are user errors
dbg
works once I've upgraded to basic-clli 0.7.0! yay thanks
I'm guessing the error was just because I was using a too-old platform for a too-new version of roc.
Matthew Phillips said:
I have noticed that the "this is definitely a compiler bug" message gets logged a lot, for things that are user errors
I think in some cases the bug is that there should be a better error message
Agus Zubiaga said:
Matthew Phillips said:
I have noticed that the "this is definitely a compiler bug" message gets logged a lot, for things that are user errors
I think in some cases the bug is that there should be a better error message
hah, fair point
Yeah, that error generally happens when somewhere in the compile we don't yet handle a case or assumed something is impossible.
Long term those should all either work or return pretty error message.
I reported an issue the other day, noticed this thread, and upgraded the basic-cli
but now I get what seems to be some macOS signing issue?
main: is already signed
I don't mean to press more on the issue, just added this here if it helps in any way :)
Are you using today's nightly release?
Anton said:
Are you using today's nightly release?
I recompiled latest main from source
Strange, I'll try to reproduce
Failed to reproduce on NixOS, will try on macOS
Using expect works great for printing things out, if the test fails it prints the locally defined variables. So I like to do things like
expect
a = myfunc input
a == expectedValue
Here it will print out the value of a
@Luke Boswell oooh I didn't realize you could do that. pretty dope!
We could update the tutorial section to make this clearer by including the output for the example, and I think it would be helpful to mention it and link to the "tests and expectations" section in the "debugging" section
For sure. I found myself a bit frustrated at not having exactly this ability - but then it was just in there! :sparkles:
dbg
just isn't printing anything for me with basic-cli
0.7.0. Am I doing something wrong?
app "dbg"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br" }
imports [pf.Stdout, pf.Task.{ Task }]
provides [main] to pf
main : Task {} I32
main =
dbg "hello"
Stdout.line "world"
$ roc run dbg.roc
world
oh it's roc dev
instead
Is there a reason dbg
is disabled for roc run
? They both don't seem to use optimizations by default
I agree, I've found this is a little confusing. I've started an idea discussion to maybe clarify what these mean.
Last updated: Jul 06 2025 at 12:14 UTC