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

internal error: entered unreachable code #242

Closed
paulyoung opened this issue Jun 5, 2021 · 9 comments
Closed

internal error: entered unreachable code #242

paulyoung opened this issue Jun 5, 2021 · 9 comments

Comments

@paulyoung
Copy link

As mentioned in dfinity/agent-rs#201 (comment), I have a canister written in Rust like this:

use ic_cdk_macros::{query};
use ic_utils_http_request::{HttpResponse, HttpRequest};

#[query]
fn http_request(request: HttpRequest) -> HttpResponse {
    HttpResponse {
        status_code: 200,
        headers: vec![],
        body: request.body.to_vec(),
        streaming_strategy: None,
    }
}

However, when I try to make a GET request via icx-proxy I get a 500 response and see this in the output from dfx start:

[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] Panicked at 'internal error: entered unreachable code', /Users/py/.cargo/registry/src/github.com-1ecc6299db9ec823/candid-0.6.21/src/parser/value.rs:326:9

I started icx-proxy with -v -v so I see the GET request being logged.

I tried to curl the proxy instead and got Replica Error (5): "IC0502: Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped: unreachable"

I did this in Motoko first as part of testing dfinity/agent-rs#195 and didn't run into this.

Could someone help me understand if I'm doing something wrong here? Thanks.

@paulyoung
Copy link
Author

From looking at https://docs.rs/crate/candid/0.6.21/source/src/parser/value.rs I suspect this might originate from:

fn id() -> crate::types::TypeId {
unreachable!();
}

@paulyoung
Copy link
Author

I see the latest version of candid is 0.7.0. Is there some mismatch because I'm using dfx version 0.7.0-beta.8 but ic-cdk version 0.3.0 exports candid version 0.6.21?

@chenyan-dfinity
Copy link
Contributor

Looks fine on the candid side. The error is due to calling IDLValue::ty(), which is not allowed. Because you cannot infer candid types from IDLValue.

Maybe related to dfinity/agent-rs#132, but I was doing a similar thing in Rust and did not see this error: https://github.com/dfinity/candid/blob/master/tools/ui/src/didjs/lib.rs#L50

@paulyoung
Copy link
Author

@chenyan-dfinity is it possible I need to add candid_method and export_service?

I tried that before but I couldn't find any documentation. I gather they're related to generating a .did file but I don't understand how they're intended to be used.

I still have a .did file around from the hello world tutorial. Could that be causing problems?

@paulyoung
Copy link
Author

paulyoung commented Jun 5, 2021

I just removed the streaming_strategy field from the definition of HttpResponse that I copied from ic-utils and it works fine now.

Based on what you said, it seems like the issue is because it's defined like this, and uses IDLValue:

#[derive(CandidType, Deserialize)]
pub struct CallbackStrategy {
    pub callback: IDLValue,
    pub token: IDLValue,
}

#[derive(CandidType, Deserialize)]
pub enum StreamingStrategy {
    Callback(CallbackStrategy),
}

#[derive(CandidType, Deserialize)]
pub struct HttpResponse {
    pub status_code: u16,
    pub headers: Vec<HeaderField>,
    #[serde(with = "serde_bytes")]
    pub body: Vec<u8>,
    pub streaming_strategy: Option<StreamingStrategy>,
}

#[derive(CandidType, Deserialize)]
pub struct StreamingCallbackHttpResponse {
    #[serde(with = "serde_bytes")]
    pub body: Vec<u8>,
    pub token: Option<IDLValue>,
}

@chenyan-dfinity
Copy link
Contributor

Right, pub token: Option<IDLValue> was the problem, and CDK cannot handle it properly. We need to change the token type to Option<candid::Func> in agent-rs.

add candid_method and export_service

Yeah, that is only used for auto-generating did files, and not related to this error. We are still trying to figure out the best way to integrate this into the CDK. For now, the best document is probably the test: https://github.com/dfinity/candid/blob/master/rust/candid/tests/types.rs#L98

@paulyoung
Copy link
Author

Thanks @chenyan-dfinity!

@paulyoung
Copy link
Author

pub token: Option<IDLValue> was the problem

token and callback I think

@paulyoung
Copy link
Author

I think StreamingCallbackHttpResponse isn't relevant here, and including it may have confused things.

ninegua pushed a commit to ninegua/candid that referenced this issue Apr 22, 2022
Also making apps private so they dont get published by lerna.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants