Skip to content

Commit 70a1cf0

Browse files
committed
Add rpc return error codes.
1 parent 4c65117 commit 70a1cf0

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

include/bitcoin/node/error.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ enum error_t : uint8_t
118118
invalid_subcomponent,
119119
extra_segment,
120120

121-
/// server (json-rpc parse codes)
122-
unexpected_parse
121+
/// server (rpc response codes)
122+
not_found,
123+
invalid_argument,
124+
not_implemented
123125
};
124126

125127
// No current need for error_code equivalence mapping.

src/error.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
4949
{ duplicate_block, "duplicate block" },
5050
{ duplicate_header, "duplicate header" },
5151

52-
/// faults
52+
// faults
5353
{ protocol1, "protocol1" },
5454
{ protocol2, "protocol2" },
5555
{ header1, "header1" },
@@ -90,7 +90,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
9090
{ confirm12, "confirm12" },
9191
{ confirm13, "confirm13" },
9292

93-
/// server (url parse codes)
93+
// server (url parse codes)
9494
{ empty_path, "empty_path" },
9595
{ invalid_number, "invalid_number" },
9696
{ invalid_hash, "invalid_hash" },
@@ -107,7 +107,11 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
107107
{ invalid_component, "invalid_component" },
108108
{ invalid_subcomponent, "invalid_subcomponent" },
109109
{ extra_segment, "extra_segment" },
110-
{ unexpected_parse, "unexpected_parse" }
110+
111+
// server (rpc response codes)
112+
{ not_found, "not_found" },
113+
{ invalid_argument, "invalid_argument" },
114+
{ not_implemented, "not_implemented" }
111115
};
112116

113117
DEFINE_ERROR_T_CATEGORY(error, "node", "node code")

test/error.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,33 @@ BOOST_AUTO_TEST_CASE(error_t__code__extra_segment__true_exected_message)
371371
BOOST_REQUIRE_EQUAL(ec.message(), "extra_segment");
372372
}
373373

374-
BOOST_AUTO_TEST_CASE(error_t__code__unexpected_parse__true_exected_message)
374+
// server (rpc response codes)
375+
376+
BOOST_AUTO_TEST_CASE(error_t__code__not_found__true_exected_message)
377+
{
378+
constexpr auto value = error::not_found;
379+
const auto ec = code(value);
380+
BOOST_REQUIRE(ec);
381+
BOOST_REQUIRE(ec == value);
382+
BOOST_REQUIRE_EQUAL(ec.message(), "not_found");
383+
}
384+
385+
BOOST_AUTO_TEST_CASE(error_t__code__invalid_argument__true_exected_message)
386+
{
387+
constexpr auto value = error::invalid_argument;
388+
const auto ec = code(value);
389+
BOOST_REQUIRE(ec);
390+
BOOST_REQUIRE(ec == value);
391+
BOOST_REQUIRE_EQUAL(ec.message(), "invalid_argument");
392+
}
393+
394+
BOOST_AUTO_TEST_CASE(error_t__code__not_implemented__true_exected_message)
375395
{
376-
constexpr auto value = error::unexpected_parse;
396+
constexpr auto value = error::not_implemented;
377397
const auto ec = code(value);
378398
BOOST_REQUIRE(ec);
379399
BOOST_REQUIRE(ec == value);
380-
BOOST_REQUIRE_EQUAL(ec.message(), "unexpected_parse");
400+
BOOST_REQUIRE_EQUAL(ec.message(), "not_implemented");
381401
}
382402

383403
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)