Rosetta Error During Canister Build

Hello :wave:

I’ve encountered a Rosetta error while attempting to deploy a canister to the local replica. During the build, DFX will pause for about 5 minutes and then eventually return the following:


rosetta error: unexpectedly need to EmulateForward on a synchronous exception x86_rip=0x7fff2017ff6f arm_pc=0x7ffe94440320 num_insts=5 inst_index=3 x86 instruction bytes: 0x56415741e5894855 0x8941505354415541
zsh: trace trap  dfx deploy RoutingTable

The canister code can be found here.

I found a similar topic here, but after checking my import statements I don’t think that’s the issue.

What typically causes this sort of error to occur?

Thanks!

It turns out i DID have an import loop, it just wasn’t in my main program.

Route.mo was importing from Sub.mo and vice versa.

After removing the loop I was able to build the canister without delay.

Hi @LightningLad91, thanks for the report! I am glad you were able to resolve the problem, but as a compiler engineer I have a few questions:

  • do you use the most recent dfx?
  • can you describe the import structure you had that exhibited the crash?

I have opened Import loops should be caught · Issue #3389 · dfinity/motoko · GitHub, maybe you can post your answers there?

Thanks for your cooperation!

Interesting, we thought we had fixed this so motoko errors gracefully on cyclic imports. Could you report which version of moc or dfx you are using?

I’ve checked out the repo, reintroduced the new fixed cyclic dependency, but can’t seem to reproduce the hang and just get a cyclic import error on some of the files:

[nix-shell:~/uNFT-Prototype/src]$ moc --package base ../../motoko-base/src Ext/Route.mo 
../../motoko-base/src/Trie.mo:244.37-244.42: warning [M0155], operator may trap for inferred type
  Nat
Ext/Route.mo:17.1-17.17: import error [M0003], file Ext/Sub.mo must not depend on itself

[nix-shell:~/uNFT-Prototype/src]$ moc --package base ../../motoko-base/src Ext/Sub.mo 
../../motoko-base/src/Trie.mo:244.37-244.42: warning [M0155], operator may trap for inferred type
  Nat
Ext/Sub.mo:2.1-2.26: import error [M0003], file Ext/Route.mo must not depend on itself

[nix-shell:~/uNFT-Prototype/src]$ moc --package base ../../motoko-base/src Ext/ 
Registry.mo  Route.mo     Services.mo  Sub.mo       

[nix-shell:~/uNFT-Prototype/src]$ moc --package base ../../motoko-base/src Ext/Services.mo 

[nix-shell:~/uNFT-Prototype/src]$ moc --package base ../../motoko-base/src Ext/Registry.mo 
Ext/Registry.mo:1.1-1.46: import error [M0009], file "motoko/util/AccountIdentifier/lib.mo" does not exist
Ext/Registry.mo:2.1-2.36: import error [M0009], file "motoko/ext/Core/lib.mo" does not exist

But maybe I’m not trying to build the right code… (or the problem is higher up in dfx somehow).

@claudio @ggreif thank you both for taking the time to follow-up on this.

I was able to recreate the problem. I simply commented out the “Route” type definition in the Sub.mo file and added an import statement for Route.mo. Please see below.

import Bool "mo:base/Bool";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
import Principal "mo:base/Principal";
import Hash "mo:base/Hash";
import Trie "mo:base/Trie";
import TrieSet "mo:base/TrieSet";
import ExtRoute "Route";


module {  
  
  public type Route = ExtRoute.Route;
  //public type Route = {
  //  from : Text;
  //  msg : Nat;
  //};

Trying to build again gave me the same Rosetta Error. I am currently running DFX version 0.11.0

Thanks, we are trying to repro this locally. One more q. Do you have a dfx.json around? Last time I looked it was not in the repository.

Sorry about that. I will add the additional files this evening.

Hi @LightningLad91
I’m on the languages team with @claudio and @ggreif (nice to meet you!)

I put an error reproducing fork here with a dfx.json file

We are tracking this issue internally. Thanks for bringing this up!

Hi @kentosugama nice to meet you too!

Thank you for addressing the issue :slight_smile: