When you call a smart contract and it fails, it returns an error location. For example:


How is this location calculated and how would someone using tezos-client determine where in a Michelson conract this error occurrs?

2 Answers 2


In order to limit storage consumption, the locations in the original .tz file that are used to originate contracts are not stored on chain. The only thing that can be reported from a runtime error is what is called the canonical location; an integer that uniquely determines the position of the FAILWITH instruction that triggered the error. It is computed as described here:

A canonical location is a single integer; the root of the node has a canonical location of zero, and each node adds one in the order of infix traversal.

  • Would this node structure be the same as the JSON version of Micheline that is used in the RPC?
    – MCH
    Jun 11, 2020 at 14:02
  • 1
    Yes, the JSON encoding of Micheline is very straightforward; the node structure is the same. Jun 13, 2020 at 13:23

How are you calling the smart contract? Some client commands will report the error location with the source.

See if this client command helps: convert script <source> from <input_format> to <output_format>. The output will include the locations if you choose JSON (or OCaml) for <output_format>.

  • Unfortunately, none of these give the line / col of each location, just ASTs with locations.
    – arvidj
    Jun 11, 2020 at 12:12
  • I would be calling from a custom RPC library. I will need to build functionality around the RPC so I need to understand it at a lower level.
    – MCH
    Jun 11, 2020 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.