mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-30 16:05:51 +00:00
@@ -41,7 +41,11 @@ namespace ripple {
|
|||||||
|
|
||||||
class STArray;
|
class STArray;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
inline void
|
||||||
|
throwFieldNotFound(SField const& field)
|
||||||
|
{
|
||||||
|
Throw<std::runtime_error>("Field not found: " + field.getName());
|
||||||
|
}
|
||||||
|
|
||||||
class STObject
|
class STObject
|
||||||
: public STBase
|
: public STBase
|
||||||
@@ -492,7 +496,7 @@ public:
|
|||||||
STBase* rf = getPField (field, true);
|
STBase* rf = getPField (field, true);
|
||||||
|
|
||||||
if (! rf)
|
if (! rf)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
if (rf->getSType () == STI_NOTPRESENT)
|
if (rf->getSType () == STI_NOTPRESENT)
|
||||||
rf = makeFieldPresent (field);
|
rf = makeFieldPresent (field);
|
||||||
@@ -552,7 +556,7 @@ private:
|
|||||||
const STBase* rf = peekAtPField (field);
|
const STBase* rf = peekAtPField (field);
|
||||||
|
|
||||||
if (! rf)
|
if (! rf)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
SerializedTypeID id = rf->getSType ();
|
SerializedTypeID id = rf->getSType ();
|
||||||
|
|
||||||
@@ -578,7 +582,7 @@ private:
|
|||||||
const STBase* rf = peekAtPField (field);
|
const STBase* rf = peekAtPField (field);
|
||||||
|
|
||||||
if (! rf)
|
if (! rf)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
SerializedTypeID id = rf->getSType ();
|
SerializedTypeID id = rf->getSType ();
|
||||||
|
|
||||||
@@ -602,7 +606,7 @@ private:
|
|||||||
STBase* rf = getPField (field, true);
|
STBase* rf = getPField (field, true);
|
||||||
|
|
||||||
if (! rf)
|
if (! rf)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
if (rf->getSType () == STI_NOTPRESENT)
|
if (rf->getSType () == STI_NOTPRESENT)
|
||||||
rf = makeFieldPresent (field);
|
rf = makeFieldPresent (field);
|
||||||
@@ -622,7 +626,7 @@ private:
|
|||||||
STBase* rf = getPField (field, true);
|
STBase* rf = getPField (field, true);
|
||||||
|
|
||||||
if (! rf)
|
if (! rf)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
if (rf->getSType () == STI_NOTPRESENT)
|
if (rf->getSType () == STI_NOTPRESENT)
|
||||||
rf = makeFieldPresent (field);
|
rf = makeFieldPresent (field);
|
||||||
@@ -642,7 +646,7 @@ private:
|
|||||||
STBase* rf = getPField (field, true);
|
STBase* rf = getPField (field, true);
|
||||||
|
|
||||||
if (! rf)
|
if (! rf)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
if (rf->getSType () == STI_NOTPRESENT)
|
if (rf->getSType () == STI_NOTPRESENT)
|
||||||
rf = makeFieldPresent (field);
|
rf = makeFieldPresent (field);
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ const STBase& STObject::peekAtField (SField const& field) const
|
|||||||
int index = getFieldIndex (field);
|
int index = getFieldIndex (field);
|
||||||
|
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
return peekAtIndex (index);
|
return peekAtIndex (index);
|
||||||
}
|
}
|
||||||
@@ -353,7 +353,7 @@ STBase& STObject::getField (SField const& field)
|
|||||||
int index = getFieldIndex (field);
|
int index = getFieldIndex (field);
|
||||||
|
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
return getIndex (index);
|
return getIndex (index);
|
||||||
}
|
}
|
||||||
@@ -453,7 +453,7 @@ STBase* STObject::makeFieldPresent (SField const& field)
|
|||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
if (!isFree ())
|
if (!isFree ())
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
return getPIndex (emplace_back(detail::nonPresentObject, field));
|
return getPIndex (emplace_back(detail::nonPresentObject, field));
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ void STObject::makeFieldAbsent (SField const& field)
|
|||||||
int index = getFieldIndex (field);
|
int index = getFieldIndex (field);
|
||||||
|
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
Throw<std::runtime_error> ("Field not found");
|
throwFieldNotFound(field);
|
||||||
|
|
||||||
const STBase& f = peekAtIndex (index);
|
const STBase& f = peekAtIndex (index);
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,22 @@
|
|||||||
#include <ripple/protocol/messages.h>
|
#include <ripple/protocol/messages.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the string loosely matches the regex.
|
||||||
|
*
|
||||||
|
* Meant for testing human-readable strings that may change over time.
|
||||||
|
*/
|
||||||
|
inline bool
|
||||||
|
matches(char const* string, char const* regex)
|
||||||
|
{
|
||||||
|
return std::regex_search(
|
||||||
|
string, std::basic_regex<char>(regex, std::regex_constants::icase));
|
||||||
|
}
|
||||||
|
|
||||||
class STTx_test : public beast::unit_test::suite
|
class STTx_test : public beast::unit_test::suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -1283,8 +1296,7 @@ public:
|
|||||||
}
|
}
|
||||||
catch (std::runtime_error const& ex)
|
catch (std::runtime_error const& ex)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT (
|
BEAST_EXPECT(matches(ex.what(), "field not found"));
|
||||||
std::strcmp (ex.what(), "Field not found") == 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1348,8 +1360,7 @@ public:
|
|||||||
}
|
}
|
||||||
catch (std::runtime_error const& ex)
|
catch (std::runtime_error const& ex)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT (
|
BEAST_EXPECT(matches(ex.what(), "field not found"));
|
||||||
std::strcmp (ex.what(), "Field not found") == 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user