# To\_candid and from\_candid Errors

**URL:** <https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [November 2, 2022, 2:58am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315 "2022-11-02T02:58:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [November 2, 2022, 2:58am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/1 "2022-11-02T02:58:49Z")

</div>

I am trying to use the `from_candid` and `to_candid` methods in a lib I’m working on, but I get these errors whenever I compile my code using the Motoko compiler in the vessel bin folder.

```auto
prim:50.30-50.42: execution error, to do: FromCandidE
prim:50.30-50.42: execution error, to do: ToCandidE

```

I tried running the code in Motoko Playground, and it works fine.  
I also updated the compiler to version `0.7.3`, but it still returns the same errors.

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [November 2, 2022, 3:04am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/2 "2022-11-02T03:04:15Z")

</div>

This behavior looks like it’s specific to the interpreter:

> <https://github.com/dfinity/motoko/blob/cdd0279b8f41e03bd7433923ca2a21c46a7d79d5/src/mo_interpreter/interpret.ml#L410-L411>

I think that’s `moc -r`. Is that what you’re using?

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [November 2, 2022, 4:10am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/3 "2022-11-02T04:10:34Z")

</div>

Yes, that’s what I’m using.

```auto
$(shell vessel bin)/moc -r $(shell vessel sources) -wasi-system-api ./tests/*Test.mo

```

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [November 2, 2022, 4:17am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/4 "2022-11-02T04:17:59Z")

</div>

I think you’d need to do something like this instead:

> [@\[M0086\] Motoko Wasm Async Functions](https://forum.dfinity.org/t/m0086-motoko-wasm-async-functions/10648/3):
>
> For unit testing. Like moc $(shell vessel sources) -wasi-system-api -o Test.wasm test/\*unit\_test\_runner.mo && wasmtime test.wasm rm -f test.wasm

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [November 2, 2022, 4:43am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/5 "2022-11-02T04:43:51Z")

</div>

Thanks! It’s working correctly now

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [November 2, 2022, 6:18am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/6 "2022-11-02T06:18:24Z")

</div>

I seem to have triggered a compiler bug. 😅  
Please report this at [Sign in to GitHub · GitHub](https://github.com/dfinity/motoko/issues/new) with the following details:  
[Compiler Bug: Motoko 0.7.3 · Issue #3539 · dfinity/motoko · GitHub](https://github.com/dfinity/motoko/issues/3539)

Motoko 0.7.3 (source qwdq7q2n-npg4rjz7-7s76jv69-kbwjwklg)

```auto
Fatal error: exception Invalid_argument("Import expression found in unit body: mo:base/Blob")
Raised at Lowering__Desugar.exp' in file "lowering/desugar.ml", line 227, characters 25-111
Called from Lowering__Desugar.typed_phrase' in file "lowering/desugar.ml", line 45, characters 16-30
Called from Lowering__Desugar.dec' in file "lowering/desugar.ml", line 688, characters 13-18
Called from Lowering__Desugar.phrase' in file "lowering/desugar.ml", line 41, characters 16-34
Called from Lowering__Desugar.dec in file "lowering/desugar.ml", line 682, characters 14-30
Called from Stdlib__list.map in file "list.ml", line 92, characters 20-23
Called from Stdlib__list.map in file "list.ml", line 92, characters 32-39
Called from Stdlib__list.map in file "list.ml", line 92, characters 32-39
Called from Stdlib__list.map in file "list.ml", line 92, characters 32-39
Called from Lowering__Desugar.transform_unit_body in file "lowering/desugar.ml", line 1068, characters 26-35
Called from Lowering__Desugar.transform_unit in file "lowering/desugar.ml", line 1107, characters 14-38
Called from Pipeline.desugar_unit in file "pipeline/pipeline.ml", line 584, characters 4-22
Called from Pipeline.compile_unit in file "pipeline/pipeline.ml", line 668, characters 16-43
Called from Pipeline.compile_files in file "pipeline/pipeline.ml", line 690, characters 19-56
Called from Diag.bind in file "lang_utils/diag.ml", line 32, characters 27-30
Called from Diag.bind in file "lang_utils/diag.ml", line 32, characters 27-30
Called from Dune __exe__ Moc.process_files in file "exes/moc.ml", line 203, characters 49-94
Called from Dune __exe__ Moc in file "exes/moc.ml", line 298, characters 4-23
make: *** [test1] Error 2

```

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [November 2, 2022, 7:46am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/7 "2022-11-02T07:46:07Z")

</div>

Thank you @tomijaga, I pinged the Motoko folks to have a look

---

<div class="post-metadata">

**Author:** ![ggreif](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ggreif/32/301_2.png) [@ggreif](https://forum.dfinity.org/u/ggreif)\
**Post date:** [November 2, 2022, 9:17am UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/8 "2022-11-02T09:17:08Z")

</div>

> [@tomijaga](#):
>
> `Import expression found in unit body`

Thanks for the report. You didn’t include a reproduction snippet, but we need something to reliably debug and fix this problem. Normally the syntax should ensure that import clauses are only appearing at the top of the file and their content gets properly resolved. In your report something unexpected is happening.

If you could provide some materials (can be a `git` repo too) that would speed up troubleshooting immensely.

---

<div class="post-metadata">

**Author:** ![tomijaga](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tomijaga/32/4389_2.png) [@tomijaga](https://forum.dfinity.org/u/tomijaga)\
**Post date:** [November 2, 2022, 5:12pm UTC](https://forum.dfinity.org/t/to-candid-and-from-candid-errors/16315/9 "2022-11-02T17:12:13Z")

</div>

I’ve added comments and links to the repo I was working on.  
The issue was I was trying to compile multiple files into a single object file.  
I wrote a bash script to help me with it but is there any command for compiling and running multiple files
