Type error expression of type ?Entry cannot produce

Hey everyone! I am currently watching the Hackin’ on The Internet Computer | ep.3 and I am writing the exact same code.
When I “dfx build” it throws an error that has to do with this part of my code:

public query func get(id0: Nat): async Entry {
func isEq(entry: Entry): Bool {
entry.id == id0;
};
Array.find(entries, isEq); //Here is the error’s line.
};

Error: Type error expression of type ?Entry cannot produce.
Can you suggest a solution?

Hi @ThanasisNta! Thanks for reaching out on this. More likely than not, this is probably due to some incompatibility issues with newer versions of the SDK and Replica, as @hansl built the Journey app using a very old version of the SDK - 0.5.5 it looks like. I can’t speak to this specific bug, but it would probably require overhauling the app to work with the current version of the SDK.

2 Likes

Hi Thanasis

The Array.find() function returns an optional Entry, not the Entry itself, so it doesn’t match your public method’s return type. (The Motoko base library has changed a bit since that video was posted).

You could either return an optional Entry from your public method, as async ?Entry , or unwrap the optional value using a switch statement, handling the null case alongside (if you need any pointers on this just let me know and I’ll provide an example).

Also, if you want to take a look at any of the base library modules for your latest installed version you can find them in the $(dfx cache show)/base directory—the comments and function signatures there are a great source of documentation.

2 Likes

Hey @Ori ! I tried to return an optional Entry from my public method as async ?Entry and now I have this error here:

Fatal error: exception Codegen.Compile.CodegenError("Local actors not supported by backend")
Raised at file "codegen/compile.ml", line 47, characters 42-64
Called from file "codegen/compile.ml", line 7117, characters 4-49
Called from file "codegen/compile.ml", line 7153, characters 20-40

I think that might be unrelated to this part of your code?

If you’re using VSCode the Motoko extension can highlight compile errors in the editor.

1 Like

I found the solution for the second error: Multiple Actors Tutorial - type error

Thank you for your help!!!

2 Likes