Add internal fatal error code

This commit is contained in:
Sergey Kuznetsov
2026-08-11 17:36:52 +01:00
parent 95526371b0
commit ecc2f07ea3
10 changed files with 83 additions and 41 deletions

View File

@@ -29,13 +29,8 @@ namespace xrpl {
namespace {
// What a host call answers when it could not be served at all: every method below hands it
// to `guarded` as the answer for a body that throws. The engine converts -1 into a fault,
// stops the run and reports `tecINTERNAL`, rather than handing the code to the contract.
//
// Named here because `Unimplemented` is not what a thrown exception is. What -1 carries is
// the meaning the two conditions share - "the host could not serve this call, and the
// contract has no business interpreting why" - and it is the fate they share too.
constexpr std::int32_t kHostInternal = hfErrorToInt(HostFunctionError::Unimplemented);
// to `guarded` as the answer for a body that throws.
constexpr std::int32_t kHostInternal = hfErrorToInt(HostFunctionError::InternalFatal);
// Copy `value` into `out` only if the whole of it fits, and answer its true length either
// way. A value too large for the guest's buffer must reach it in no part: a prefix would

View File

@@ -124,7 +124,7 @@ getAnyFieldData(FieldValue const& variantObj)
return Bytes((*u)->begin(), (*u)->end());
// Unreachable: the variant only holds the two alternatives above. If not, it is an
// xrpld bug, and `guarded` turns the throw into -1, which stops the run ->
// xrpld bug, and `guarded` turns the throw into `InternalFatal`, which stops the run ->
// tecINTERNAL.
Throw<std::runtime_error>("field value variant holds neither alternative"); // LCOV_EXCL_LINE
}

View File

@@ -292,7 +292,10 @@ TEST_F(WasmVMTest, FatalHostErrorStopsRun)
return std::unexpected(refused);
});
for (auto const error : {HostFunctionError::Unimplemented, HostFunctionError::NoMemExported})
for (auto const error :
{HostFunctionError::InternalFatal,
HostFunctionError::Unimplemented,
HostFunctionError::NoMemExported})
{
refused = error;