Stream: beginners

Topic: Debugging roc?


view this post on Zulip Asbjørn Olling (Dec 01 2023 at 12:30):

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?

view this post on Zulip Anton (Dec 01 2023 at 13:07):

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

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 13:21):

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?

view this post on Zulip Richard Feldman (Dec 01 2023 at 13:23):

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

view this post on Zulip Richard Feldman (Dec 01 2023 at 13:23):

but more relevantly here, the new way we're doing things fixes a bunch of bugs with the old implementation :big_smile:

view this post on Zulip Matthew Phillips (Dec 01 2023 at 13:25):

I have noticed that the "this is definitely a compiler bug" message gets logged a lot, for things that are user errors

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 13:27):

dbg works once I've upgraded to basic-clli 0.7.0! yay thanks

view this post on Zulip Asbjørn Olling (Dec 01 2023 at 13:28):

I'm guessing the error was just because I was using a too-old platform for a too-new version of roc.

view this post on Zulip Agus Zubiaga (Dec 01 2023 at 13:30):

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

view this post on Zulip Matthew Phillips (Dec 01 2023 at 13:32):

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

view this post on Zulip Brendan Hansknecht (Dec 01 2023 at 15:17):

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.

view this post on Zulip Johan Lindskogen (Dec 01 2023 at 16:25):

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 :)

view this post on Zulip Anton (Dec 01 2023 at 16:27):

Are you using today's nightly release?

view this post on Zulip Johan Lindskogen (Dec 01 2023 at 16:28):

Anton said:

Are you using today's nightly release?

I recompiled latest main from source

view this post on Zulip Anton (Dec 01 2023 at 16:31):

Strange, I'll try to reproduce

view this post on Zulip Anton (Dec 01 2023 at 16:45):

Failed to reproduce on NixOS, will try on macOS

view this post on Zulip Luke Boswell (Dec 01 2023 at 17:20):

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

view this post on Zulip Asbjørn Olling (Dec 02 2023 at 14:01):

@Luke Boswell oooh I didn't realize you could do that. pretty dope!

view this post on Zulip Luke Boswell (Dec 02 2023 at 19:55):

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

view this post on Zulip Asbjørn Olling (Dec 02 2023 at 20:00):

For sure. I found myself a bit frustrated at not having exactly this ability - but then it was just in there! :sparkles:

view this post on Zulip timotree (Dec 07 2023 at 22:16):

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

view this post on Zulip timotree (Dec 07 2023 at 22:17):

oh it's roc dev instead

view this post on Zulip timotree (Dec 07 2023 at 22:17):

Is there a reason dbg is disabled for roc run? They both don't seem to use optimizations by default

view this post on Zulip Luke Boswell (Dec 07 2023 at 22:43):

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