Motoko - try/catch/finally - Finally does not have system context?

I had a call to a <system> type function in a finally and the compiler was angry despite the finally being in a system function that returned async.

Maybe this is intentional since you’re only supposed to be doing clean up? But if I have a fairly generic class and most things are system by default then it makes the feature a lot less useful.

Ultimately, what is allowed in a finally.must be able to run in a system level cleanup function, which is pretty locked down in what it can do IIRC.

We might be able to relax it a little, but not much more.

I think that is fine, but it would be nice if the compiler could identify the specific use case as it was very confusing since it says I was not in a valid system context when I was in an async function. Something like “system context is not allowed in a finally” or something like that will likely save future travelers some time.

2 Likes