# Weird error: I don't understand why execution is interrupted

**URL:** <https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883>\
**Category:** Motoko\
**Created:** [October 6, 2024, 6:05pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883 "2024-10-06T18:05:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [October 6, 2024, 6:05pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/1 "2024-10-06T18:05:24Z")

</div>

I have:

```auto
        Debug.print("A6");
        let inst = await pm.installPackageWithPreinstalledModules({
            packageName = "icpack";
            version = "0.0.1"; // TODO: should be `"stable"`
            preinstalledModules = [("frontend", frontend)];
            repo;
            caller;
            callback = ?bootstrapBackendCallback;
        });
        Debug.print("A7");

```

and

```auto
    public shared({caller}) func installPackageWithPreinstalledModules({
        packageName: Common.PackageName;
        version: Common.Version;
        preinstalledModules: [(Text, Principal)];
        repo: Common.RepositoryPartitionRO;
        caller: Principal;
        callback: ?(shared ({
            installationId: Common.InstallationId;
            can: Principal;
            caller: Principal;
        }) -> async ());
    })
        : async {installationId: Common.InstallationId}
    {
        Debug.print("B1");
        onlyOwner(caller);
        Debug.print("B2");

        await* _installPackage({caller; packageName; version; preinstalledModules = ?preinstalledModules; repo; callback});
    };

```

How so that `A6` is printed and `B1` isn’t?!

`...`

`2024-10-06 17:54:12.074027733 UTC: [Canister by6od-j4aaa-aaaaa-qaadq-cai] A6`

`2024-10-06 17:54:13.406173747 UTC: [Canister 6zqe7-uuaaa-aaaaa-qacia-cai] Indirect caller: IC0503: Error from Canister 66rcl-zmaaa-aaaaa-qaciq-cai: Canister called `ic0.trap` with message: IDL error: unexpected IDL type when parsing Principal.`

`Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly`

There isn’t anything between `A6` and `B1` that would prevent `B1` to be printed. That a one-way method fails with an error (`Indirect caller` error is printed by `Debug.print` in an one-way tunction) during execution of the ongoing code should not prevent `B1` to be printed… I misunderstand something.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [October 6, 2024, 7:57pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/2 "2024-10-06T19:57:00Z")

</div>

Your candid types are off so the function is never being called…not at. Place to inspect, but check that your types exactly line up.

Something is wrong with a principal. It expects one but finds something else. opt principal maybe?

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [October 6, 2024, 8:08pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/3 "2024-10-06T20:08:52Z")

</div>

I told that I also have a trouble with a one-way function. (I do understand that I pass a wrong type to it.) But why `A6` is printed and `B1` isn’t. Why? It is in another fiber of execution and should not be affected by the calling (or not) the one-way function. What is wrong HERE?

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [October 6, 2024, 8:38pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/4 "2024-10-06T20:38:59Z")

</div>

@skilesare The following runs just fine (despite the one-way function fails), printing all the 1000 numbers:

```auto
import Debug "mo:base/Debug";

actor {
  public shared func greet() : async () {
    oneWay();
    var i = 0;
    while (i < 1000) {
      Debug.print(debug_show(i));
      i += 1;
    };
  };

  public shared func oneWay(): () {
    let _ = 1 / 0;
  }
};

```

But my function in a way that I can’t understand fails to print `B1`. Why?! Is refusal to print `B1` somehow related with calling a one-way function above in my code (not shown)?

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [October 6, 2024, 9:52pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/5 "2024-10-06T21:52:15Z")

</div>

InstallPackageWithPreinstall is never getting executed because the canister can’t interpret your parameters

The trap is from  
Message parsing code not from inside your function.

‘’’  
`Canister called ` ic0.trap`with message: IDL error: unexpected IDL type when parsing Principal.`  
‘’’

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [October 6, 2024, 9:55pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/6 "2024-10-06T21:55:03Z")

</div>

See [Motoko: Interesting one shot behavior - #2 by claudio](https://forum.dfinity.org/t/motoko-interesting-one-shot-behavior/16086/2) for some one shot explanations.

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [October 7, 2024, 3:01am UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/7 "2024-10-07T03:01:30Z")

</div>

How so, “canister can’t interpret your parameters”? I call a Motoko function directly, not through some fancy e.g. management canister method. It looks like that the parameters cannot be mis-interpreted (but they are, how so?)

And yes, “Message parsing code not from inside your function” because it starts with `Indirect caller:`, this way I log exceptions in a one-way function (so, yes, not from inside my function).

What I don’t understand: If message passing to my function is correct, then why isn’t `B1` printed?!! The message passing bug is in another one-way function (not from inside my functions). Then how come that control does not reach `Debug.print("B1")`?!

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [October 7, 2024, 11:16am UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/8 "2024-10-07T11:16:22Z")

</div>

I’ve realized what happened:

The `IC.install_code` is run before my code in an one-way function. And it is either not installed altogether or installed to late (after `await pm.installPackageWithPreinstalledModules(...)`. So, I am calling a canister with no code in it.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [October 7, 2024, 12:38pm UTC](https://forum.dfinity.org/t/weird-error-i-dont-understand-why-execution-is-interrupted/35883/9 "2024-10-07T12:38:26Z")

</div>

> [@qwertytrewq](#):
>
> nexpected IDL type when parsing Principal

That makes sense. The error comes from [terraform-provider-ic/internal/provider/arg.go at aec0f7d61e5e3e0c2920db6f5394ef1a23a3d0cb · dfinity/terraform-provider-ic · GitHub](https://github.com/dfinity/terraform-provider-ic/blob/aec0f7d61e5e3e0c2920db6f5394ef1a23a3d0cb/internal/provider/arg.go#L76) which is in the terraform provider.
