Repository: aptos-labs/aptos-core
File: types/src/transaction/multisig.rs (Rust)

Code before:
/// Contains information about execution failure.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ExecutionError {
    // The module where the error occurred.
    pub abort_location: String,
    pub error_type: String,
    // The detailed error code explaining which error occurred.
    pub error_code: u64,
}

impl TryFrom<VMStatus> for ExecutionError {
    type Error = anyhow::Error;

    fn try_from(status: VMStatus) -> anyhow::Result<ExecutionError> {
        match status {
            VMStatus::Error {
                status_code: error, ..
            } => Ok(ExecutionError {
                error_type: String::from("VMError"),
                abort_location: String::from(""),
                error_code: error as u64,
            }),
            VMStatus::MoveAbort {
                location: abort_location,
                code: error_code,
                ..
            } => Ok(ExecutionError {
                error_type: String::from("MoveAbort"),
                abort_location: format!("{:?}", abort_location),
                error_code,
            }),
            VMStatus::ExecutionFailure {
                status_code,
                location,
                function: _,
                code_offset: _,
                message: _,
                sub_status: _,
            } => Ok(ExecutionError {
                error_type: String::from("MoveExecutionFailure"),
                abort_location: format!("{:?}", location),
                error_code: status_code as u64,
            }),
            _ => Err(anyhow::anyhow!(
                "Unknown error from vm status cannot be converted into `ExecutionError`: {:?}",
                status
            )),
        }
    }
}


Review comment (suggestion):
Let's add a note that we have to ignore here the message because this error is serialized for multisig transactions (here: https://github.com/aptos-labs/aptos-core/blob/5454f958c502caa03f325c2ac9779620652152a6/aptos-move/aptos-vm/src/aptos_vm.rs#L1407)

Code after:
/// Contains information about execution failure.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ExecutionError {
    // The module where the error occurred.
    pub abort_location: String,
    pub error_type: String,
    // The detailed error code explaining which error occurred.
    pub error_code: u64,
}

impl TryFrom<VMStatus> for ExecutionError {
    type Error = anyhow::Error;

    fn try_from(status: VMStatus) -> anyhow::Result<ExecutionError> {
        match status {
            VMStatus::Error {
                status_code: error, ..
            } => Ok(ExecutionError {
                error_type: String::from("VMError"),
                abort_location: String::from(""),
                error_code: error as u64,
            }),
            VMStatus::MoveAbort {
                location: abort_location,
                code: error_code,
                // Note that we ignore the message here because ExecutionError has to be serialized
                // for multisig transactions and the serialization is not expected to fail.
                message: _,
            } => Ok(ExecutionError {
                error_type: String::from("MoveAbort"),
                abort_location: format!("{:?}", abort_location),
                error_code,
            }),
            VMStatus::ExecutionFailure {
                status_code,
                location,
                function: _,
                code_offset: _,
                message: _,
                sub_status: _,
            } => Ok(ExecutionError {
                error_type: String::from("MoveExecutionFailure"),
                abort_location: format!("{:?}", location),
                error_code: status_code as u64,
            }),
            _ => Err(anyhow::anyhow!(
                "Unknown error from vm status cannot be converted into `ExecutionError`: {:?}",
                status
            )),
        }
    }