You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Virtual Machine (VM) produces a lot of different error kinds. Right now VM's methods signatures don't provide a knowledge about produced errors. Each VM method returns a general type of error and there is no way to know, without reading source code, which errors might be produced and which errors will never appear. This is an error-prone and unfriendly API. When new error type will be created a compiler will not make a tip about that and new error might be unhandled.
Proposition
Error hierarchy should allow a compiler to make a tip when we forgot to handle some error kind.
Method signatures must reflect possible errors. For example, Wasm.apply should produce InitializationError, TrapError, InternalVmError and we need to know this from the signature of the method apply.
Possible solution
Create sealed traits for each method in a VM, for invoke - InvokationError, for getVmState - GetVmStateError and so on. InvokationError sealed trait should become a parent for each error which might be produced in the invoke method. It allows the compiler to detect unhandled errors in pattern-matching through exhaustiveness check.
For example: sealed trait InternalVmError extends ApplyError with InvokeError with GetVmStateError means that InternalVmError can be produced by methods apply, invoke, getVmState
If there are more suitable solutions with the less boilerplate code we should consider them too.
The text was updated successfully, but these errors were encountered:
Motivation
Virtual Machine (VM) produces a lot of different error kinds. Right now VM's methods signatures don't provide a knowledge about produced errors. Each VM method returns a general type of error and there is no way to know, without reading source code, which errors might be produced and which errors will never appear. This is an error-prone and unfriendly API. When new error type will be created a compiler will not make a tip about that and new error might be unhandled.
Proposition
Wasm.apply
should produceInitializationError
,TrapError
,InternalVmError
and we need to know this from the signature of the methodapply
.Possible solution
Create sealed traits for each method in a VM, for
invoke
-InvokationError
, forgetVmState
-GetVmStateError
and so on.InvokationError
sealed trait should become a parent for each error which might be produced in theinvoke
method. It allows the compiler to detect unhandled errors in pattern-matching through exhaustiveness check.For example:
sealed trait InternalVmError extends ApplyError with InvokeError with GetVmStateError
means that InternalVmError can be produced by methods apply, invoke, getVmStateIf there are more suitable solutions with the less boilerplate code we should consider them too.
The text was updated successfully, but these errors were encountered: