Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade basic-cli to purity inference roc panics Option::unwrap() on a None value #7208

Open
lukewilliamboswell opened this issue Nov 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@lukewilliamboswell
Copy link
Collaborator

In this commit

$ roc examples/tcp-client.roc
thread '<unnamed>' panicked at crates/compiler/mono/src/ir.rs:6191:56:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
app [main!] { pf: platform "../platform/main.roc" }

import pf.Tcp
import pf.Stdout
import pf.Stdin
import pf.Stderr

main! = \{} ->
    when run! {} is
        Ok {} -> Ok {}
        Err err -> handleErr! err

handleErr! : []_ => Result {} _
handleErr! = \error ->
    when error is
        TcpConnectErr err ->
            errStr = Tcp.connectErrToStr err
            Stderr.line!
                """
                Failed to connect: $(errStr)

                If you don't have anything listening on port 8085, run:
                \$ nc -l 8085

                If you want an echo server you can run:
                $ ncat -e \$(which cat) -l 8085
                """

        TcpReadBadUtf8 _ ->
            Stderr.line! "Received invalid UTF-8 data"

        TcpReadErr err ->
            errStr = Tcp.streamErrToStr err
            Stderr.line! "Error while reading: $(errStr)"

        TcpWriteErr err ->
            errStr = Tcp.streamErrToStr err
            Stderr.line! "Error while writing: $(errStr)"

        other -> Stderr.line! "Got other error: $(Inspect.toStr other)"

run! : {} => Result {} _
run! = \{} ->

    stream = try Tcp.connect! "127.0.0.1" 8085

    try Stdout.line! "Connected!"

    loop! {} \_ ->
        Result.map (tick! stream) Step

tick! : Tcp.Stream => Result {} _
tick! = \stream ->
    try Stdout.write! "> "

    outMsg = try Stdin.line! {}

    try Tcp.writeUtf8! stream "$(outMsg)\n"

    inMsg = try Tcp.readLine! stream

    Stdout.line! "< $(inMsg)"

loop! : state, (state => Result [Step state, Done done] err) => Result done err
loop! = \state, fn! ->
    when fn! state is
        Err err -> Err err
        Ok (Done done) -> Ok done
        Ok (Step next) -> loop! next fn!
@lukewilliamboswell lukewilliamboswell added the bug Something isn't working label Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant