Closed jolestar closed 7 months ago
What's the difference of returning Ok(NativeResult::err(...))
and Err(PartialVMError)
?
What's the difference of returning
Ok(NativeResult::err(...))
andErr(PartialVMError)
?
NativeResult
What's the difference of returning
Ok(NativeResult::err(...))
andErr(PartialVMError)
?NativeResult = Result<T, PartialVMError>
NativeResult
defination: https://github.com/rooch-network/move/blob/47bb63611844e547fed85c9fe7f66d508caa684a/language/move-vm/types/src/natives/function.rs#L35C15-L35C15
Result<T, PartialVMError> is PartialVMResult<T>
defined here, which is the return type of native functions.
I see that in some native function error is returned with Err(PartialVMError::new(...)), some is returned with Ok(NativeResult::err(...))
I made a mistake on the previous, PartialVMError has no location, VMError has a location.
So, when returning with error, when to return Err(PartialVMError)
, when to return Ok(NativeResult::err)
?
In the VM, if we know the location, return VMError. Otherwise, return PartialVMError and let the invoker set the location.
Some native functions directly raise the error code.
https://github.com/rooch-network/rooch/blob/4a649e19a2040d8e3c9378f0701bf8217bf84fee/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1_recoverable.rs#L50-L52
This needs to be converted by the
moveos_types::move_std::error
function, likehttps://github.com/rooch-network/rooch/blob/4a649e19a2040d8e3c9378f0701bf8217bf84fee/moveos/moveos-stdlib/src/natives/moveos_stdlib/raw_table/mod.rs#L482-L485