Repository: aptos-labs/aptos-core
File: aptos-move/aptos-vm/src/errors.rs (Rust)

Code before:
        VMStatus::Executed => VMStatus::Executed,
        VMStatus::MoveAbort { location, code, .. }
            if !APTOS_TRANSACTION_VALIDATION.is_account_module_abort(&location) =>
        {
            let (category, reason) = error_split(code);
            let err_msg = format!("[aptos_vm] Unexpected success epilogue Move abort: {:?}::{:?} (Category: {:?} Reason: {:?})",
			location, code, category, reason);
            speculative_error!(log_context, err_msg.clone());
            VMStatus::error(
                StatusCode::UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION,
                Some(err_msg),
            )
        },

        VMStatus::MoveAbort {
            location,
            code,
            message,
        } => match error_split(code) {
            (LIMIT_EXCEEDED, ECANT_PAY_GAS_DEPOSIT) => VMStatus::MoveAbort {
                location,
                code,
                message,
            },
            (category, reason) => {
                let err_msg = format!("[aptos_vm] Unexpected success epilogue Move abort: {:?}::{:?} (Category: {:?} Reason: {:?})",
			    location, code, category, reason);
                speculative_error!(log_context, err_msg.clone());
                VMStatus::error(
                    StatusCode::UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION,
                    Some(err_msg),
                )
            },
        },
        // Speculative errors are returned for caller to handle.
        e @ VMStatus::Error {
            status_code:
                StatusCode::SPECULATIVE_EXECUTION_ABORT_ERROR
                | StatusCode::DELAYED_FIELD_OR_BLOCKSTM_CODE_INVARIANT_ERROR,
            ..
        } => e,
        status => {
            let err_msg = format!("[aptos_vm] Unexpected success epilogue error: {:?}", status);
            speculative_error!(log_context, err_msg.clone());
            VMStatus::Error {
                status_code: StatusCode::UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION,
                sub_status: status.sub_status(),
                message: Some(err_msg),
            }
        },
    })

Review comment (bug):
can we also add a message from `MoveAbort` here to this `err_msg`? Then we can add prologue error messages in the future and connect to here so debugging is easier.

Code after:
            VMStatus::Error {
                status_code: StatusCode::UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION,
                sub_status: status.sub_status(),
                message: None,
            }
        },
    })
}

/// Checks for only Move aborts or successful execution.
/// Any other errors are mapped to the invariant violation
/// `UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION`
pub fn convert_epilogue_error(
    error: VMError,
    log_context: &AdapterLogSchema,
) -> Result<(), VMStatus> {
    let status = error.into_vm_status();
    Err(match status {
        VMStatus::Executed => VMStatus::Executed,
        VMStatus::MoveAbort {
            location,
            code,
            message,
        } if !APTOS_TRANSACTION_VALIDATION.is_account_module_abort(&location) => {
            let (category, reason) = error_split(code);
            let mut err_msg = format!(
                "[aptos_vm] Unexpected success epilogue Move abort: {:?}::{:?} (Category: {:?} Reason: {:?})",
                location, code, category, reason
            );
            if let Some(abort_msg) = message {
                err_msg.push_str(" Message: ");
                err_msg.push_str(&abort_msg);
            }
            speculative_error!(log_context, err_msg.clone());
            VMStatus::error(
                StatusCode::UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION,
                Some(err_msg),
            )
        },

        VMStatus::MoveAbort {
            location,
            code,
            message,
        } => match error_split(code) {
            (LIMIT_EXCEEDED, ECANT_PAY_GAS_DEPOSIT) => VMStatus::MoveAbort {
                location,
                code,
                message,
            },
            (category, reason) => {