未验证 提交 eaad0eed 编写于 作者: K Kevin Heifner 提交者: GitHub

Merge pull request #5787 from EOSIO/abi-serializer-improve-error-messages

Verbose ABI serialization errors
此差异已折叠。
Subproject commit 4dc8375d7d3e02ab1177ab5c22835f75b45c845a
Subproject commit aac546b419891ef6644e0d99dba5e8d33f70401d
......@@ -79,7 +79,10 @@ void chain_api_plugin::plugin_startup() {
auto ro_api = app().get_plugin<chain_plugin>().get_read_only_api();
auto rw_api = app().get_plugin<chain_plugin>().get_read_write_api();
app().get_plugin<http_plugin>().add_api({
auto& _http_plugin = app().get_plugin<http_plugin>();
ro_api.set_shorten_abi_errors( !_http_plugin.verbose_errors() );
_http_plugin.add_api({
CHAIN_RO_CALL(get_info, 200l),
CHAIN_RO_CALL(get_block, 200),
CHAIN_RO_CALL(get_block_header_state, 200),
......
......@@ -1217,7 +1217,7 @@ static float64_t to_softfloat64( double d ) {
return *reinterpret_cast<float64_t*>(&d);
}
static fc::variant get_global_row( const database& db, const abi_def& abi, const abi_serializer& abis, const fc::microseconds& abi_serializer_max_time_ms ) {
fc::variant get_global_row( const database& db, const abi_def& abi, const abi_serializer& abis, const fc::microseconds& abi_serializer_max_time_ms, bool shorten_abi_errors ) {
const auto table_type = get_table_type(abi, N(global));
EOS_ASSERT(table_type == read_only::KEYi64, chain::contract_table_query_exception, "Invalid table type ${type} for table global", ("type",table_type));
......@@ -1230,7 +1230,7 @@ static fc::variant get_global_row( const database& db, const abi_def& abi, const
vector<char> data;
read_only::copy_inline_row(*it, data);
return abis.binary_to_variant(abis.get_table_type(N(global)), data, abi_serializer_max_time_ms);
return abis.binary_to_variant(abis.get_table_type(N(global)), data, abi_serializer_max_time_ms, shorten_abi_errors );
}
read_only::get_producers_result read_only::get_producers( const read_only::get_producers_params& p ) const {
......@@ -1275,12 +1275,12 @@ read_only::get_producers_result read_only::get_producers( const read_only::get_p
}
copy_inline_row(*kv_index.find(boost::make_tuple(table_id->id, it->primary_key)), data);
if (p.json)
result.rows.emplace_back(abis.binary_to_variant(abis.get_table_type(N(producers)), data, abi_serializer_max_time));
result.rows.emplace_back( abis.binary_to_variant( abis.get_table_type(N(producers)), data, abi_serializer_max_time, shorten_abi_errors ) );
else
result.rows.emplace_back(fc::variant(data));
}
result.total_producer_vote_weight = get_global_row(d, abi, abis, abi_serializer_max_time)["total_producer_vote_weight"].as_double();
result.total_producer_vote_weight = get_global_row(d, abi, abis, abi_serializer_max_time, shorten_abi_errors)["total_producer_vote_weight"].as_double();
return result;
}
......@@ -1668,7 +1668,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
if ( it != idx.end() ) {
vector<char> data;
copy_inline_row(*it, data);
result.total_resources = abis.binary_to_variant( "user_resources", data, abi_serializer_max_time );
result.total_resources = abis.binary_to_variant( "user_resources", data, abi_serializer_max_time, shorten_abi_errors );
}
}
......@@ -1679,7 +1679,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
if ( it != idx.end() ) {
vector<char> data;
copy_inline_row(*it, data);
result.self_delegated_bandwidth = abis.binary_to_variant( "delegated_bandwidth", data, abi_serializer_max_time );
result.self_delegated_bandwidth = abis.binary_to_variant( "delegated_bandwidth", data, abi_serializer_max_time, shorten_abi_errors );
}
}
......@@ -1690,7 +1690,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
if ( it != idx.end() ) {
vector<char> data;
copy_inline_row(*it, data);
result.refund_request = abis.binary_to_variant( "refund_request", data, abi_serializer_max_time );
result.refund_request = abis.binary_to_variant( "refund_request", data, abi_serializer_max_time, shorten_abi_errors );
}
}
......@@ -1701,7 +1701,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
if ( it != idx.end() ) {
vector<char> data;
copy_inline_row(*it, data);
result.voter_info = abis.binary_to_variant( "voter_info", data, abi_serializer_max_time );
result.voter_info = abis.binary_to_variant( "voter_info", data, abi_serializer_max_time, shorten_abi_errors );
}
}
}
......@@ -1727,7 +1727,7 @@ read_only::abi_json_to_bin_result read_only::abi_json_to_bin( const read_only::a
auto action_type = abis.get_action_type(params.action);
EOS_ASSERT(!action_type.empty(), action_validate_exception, "Unknown action ${action} in contract ${contract}", ("action", params.action)("contract", params.code));
try {
result.binargs = abis.variant_to_binary(action_type, params.args, abi_serializer_max_time);
result.binargs = abis.variant_to_binary( action_type, params.args, abi_serializer_max_time, shorten_abi_errors );
} EOS_RETHROW_EXCEPTIONS(chain::invalid_action_args_exception,
"'${args}' is invalid args for action '${action}' code '${code}'. expected '${proto}'",
("args", params.args)("action", params.action)("code", params.code)("proto", action_abi_to_variant(abi, action_type)))
......@@ -1744,7 +1744,7 @@ read_only::abi_bin_to_json_result read_only::abi_bin_to_json( const read_only::a
abi_def abi;
if( abi_serializer::to_abi(code_account.abi, abi) ) {
abi_serializer abis( abi, abi_serializer_max_time );
result.args = abis.binary_to_variant( abis.get_action_type( params.action ), params.binargs, abi_serializer_max_time );
result.args = abis.binary_to_variant( abis.get_action_type( params.action ), params.binargs, abi_serializer_max_time, shorten_abi_errors );
} else {
EOS_ASSERT(false, abi_not_found_exception, "No ABI found for ${contract}", ("contract", params.code));
}
......
......@@ -68,6 +68,7 @@ uint64_t convert_to_type(const string& str, const string& desc);
class read_only {
const controller& db;
const fc::microseconds abi_serializer_max_time;
bool shorten_abi_errors = true;
public:
static const string KEYi64;
......@@ -77,6 +78,8 @@ public:
void validate() const {}
void set_shorten_abi_errors( bool f ) { shorten_abi_errors = f; }
using get_info_params = empty;
struct get_info_results {
......@@ -434,7 +437,7 @@ public:
copy_inline_row(*itr2, data);
if (p.json) {
result.rows.emplace_back(abis.binary_to_variant(abis.get_table_type(p.table), data, abi_serializer_max_time));
result.rows.emplace_back( abis.binary_to_variant( abis.get_table_type(p.table), data, abi_serializer_max_time, shorten_abi_errors ) );
} else {
result.rows.emplace_back(fc::variant(data));
}
......@@ -495,7 +498,7 @@ public:
copy_inline_row(*itr, data);
if (p.json) {
result.rows.emplace_back(abis.binary_to_variant(abis.get_table_type(p.table), data, abi_serializer_max_time));
result.rows.emplace_back( abis.binary_to_variant( abis.get_table_type(p.table), data, abi_serializer_max_time, shorten_abi_errors ) );
} else {
result.rows.emplace_back(fc::variant(data));
}
......
......@@ -606,4 +606,8 @@ namespace eosio {
return (!my->listen_endpoint || my->listen_endpoint->address().is_loopback());
}
bool http_plugin::verbose_errors()const {
return verbose_http_errors;
}
}
......@@ -60,12 +60,12 @@ namespace eosio {
* called with the response code and body.
*
* The handler will be called from the appbase application io_service
* thread. The callback can be called from any thread and will
* thread. The callback can be called from any thread and will
* automatically propagate the call to the http thread.
*
* The HTTP service will run in its own thread with its own io_service to
* make sure that HTTP request processing does not interfer with other
* plugins.
* plugins.
*/
class http_plugin : public appbase::plugin<http_plugin>
{
......@@ -85,7 +85,7 @@ namespace eosio {
void add_handler(const string& url, const url_handler&);
void add_api(const api_description& api) {
for (const auto& call : api)
for (const auto& call : api)
add_handler(call.first, call.second);
}
......@@ -95,6 +95,8 @@ namespace eosio {
bool is_on_loopback() const;
bool is_secure() const;
bool verbose_errors()const;
private:
std::unique_ptr<class http_plugin_impl> my;
};
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册