Skip to content

Commit e27c304

Browse files
author
Andrianto Lie
committed
Update FC_ASSERT for abi_generator and abi_serializer
Update FC_ASSERT for apply_context, authorization_manager, authority_checker Update FC_ASSERT for all the plugins Update FC_ASSERT for block_header_state, block_log, chain_id_type, eosio_contract Update FC_ASSERT for fork_database, resource_limits, transaction, transaction_context, cleos main, asset Update FC_ASSERT for warm, cleos http, controller Update FC_ASSERT for resource_limits, action, block_timestamp, fixed_key, symbol, wasm Update FC_THROW to be more descriptive using EOS_THROW Update mongodb FC_ASSERT Fix rebase conflict Cleanup
1 parent 39ed9f2 commit e27c304

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+597
-387
lines changed

libraries/abi_generator/include/eosio/abi_generator/abi_generator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace eosio {
8989
inline string is_clause_decl( string line ) {
9090
smatch match;
9191
if ( regex_match( line, match, regex("(###[ ]+CLAUSE[ ]+NAME[ ]*:[ ]*)(.*)", regex_constants::ECMAScript) ) ) {
92-
FC_ASSERT( match.size() == 3, "Error, malformed clause declaration" );
92+
EOS_ASSERT( match.size() == 3, invalid_ricardian_clause_exception, "Error, malformed clause declaration" );
9393
return match[2].str();
9494
}
9595
return {};
@@ -98,7 +98,7 @@ namespace eosio {
9898
inline string is_action_decl( string line ) {
9999
smatch match;
100100
if ( regex_match( line, match, regex("(##[ ]+ACTION[ ]+NAME[ ]*:[ ]*)(.*)", regex_constants::ECMAScript) ) ) {
101-
FC_ASSERT( match.size() == 3, "Error, malformed action declaration" );
101+
EOS_ASSERT( match.size() == 3, invalid_ricardian_action_exception, "Error, malformed action declaration" );
102102
return match[2].str();
103103
}
104104
return {};
@@ -137,7 +137,7 @@ namespace eosio {
137137
if ( !(_name = is_clause_decl( line )).empty() ) {
138138
if ( !first_time ) {
139139
if (body.str().empty() ) {
140-
FC_ASSERT( false, "Error, invalid input in ricardian clauses, no body found" );
140+
EOS_ASSERT( false, invalid_ricardian_clause_exception, "Error, invalid input in ricardian clauses, no body found" );
141141
}
142142
_clauses.emplace_back( name, body.str() );
143143
body.str("");

libraries/chain/abi_serializer.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <eosio/chain/chain_config.hpp>
99
#include <eosio/chain/transaction.hpp>
1010
#include <eosio/chain/asset.hpp>
11+
#include <eosio/chain/exceptions.hpp>
1112
#include <fc/io/raw.hpp>
1213
#include <boost/algorithm/string/predicate.hpp>
1314
#include <fc/io/varint.hpp>
@@ -109,8 +110,8 @@ namespace eosio { namespace chain {
109110
structs[st.name] = st;
110111

111112
for( const auto& td : abi.types ) {
112-
FC_ASSERT(_is_type(td.type, 0, deadline, max_serialization_time), "invalid type", ("type",td.type));
113-
FC_ASSERT(!_is_type(td.new_type_name, 0, deadline, max_serialization_time), "type already exists", ("new_type_name",td.new_type_name));
113+
EOS_ASSERT(_is_type(td.type, 0, deadline, max_serialization_time), invalid_type_inside_abi, "invalid type", ("type",td.type));
114+
EOS_ASSERT(!_is_type(td.new_type_name, 0, deadline, max_serialization_time), duplicate_abi_type_def_exception, "type already exists", ("new_type_name",td.new_type_name));
114115
typedefs[td.new_type_name] = td.type;
115116
}
116117

@@ -127,11 +128,11 @@ namespace eosio { namespace chain {
127128
* The ABI vector may contain duplicates which would make it
128129
* an invalid ABI
129130
*/
130-
FC_ASSERT( typedefs.size() == abi.types.size() );
131-
FC_ASSERT( structs.size() == abi.structs.size() );
132-
FC_ASSERT( actions.size() == abi.actions.size() );
133-
FC_ASSERT( tables.size() == abi.tables.size() );
134-
FC_ASSERT( error_messages.size() == abi.error_messages.size() );
131+
EOS_ASSERT( typedefs.size() == abi.types.size(), duplicate_abi_type_def_exception, "duplicate type definition detected" );
132+
EOS_ASSERT( structs.size() == abi.structs.size(), duplicate_abi_struct_def_exception, "duplicate struct definition detected" );
133+
EOS_ASSERT( actions.size() == abi.actions.size(), duplicate_abi_action_def_exception, "duplicate action definition detected" );
134+
EOS_ASSERT( tables.size() == abi.tables.size(), duplicate_abi_table_def_exception, "duplicate table definition detected" );
135+
EOS_ASSERT( error_messages.size() == abi.error_messages.size(), duplicate_abi_err_msg_def_exception, "duplicate error message definition detected" );
135136

136137
validate(deadline, max_serialization_time);
137138
}
@@ -147,7 +148,7 @@ namespace eosio { namespace chain {
147148

148149
int abi_serializer::get_integer_size(const type_name& type) const {
149150
string stype = type;
150-
FC_ASSERT( is_integer(type), "${stype} is not an integer type", ("stype",stype));
151+
EOS_ASSERT( is_integer(type), invalid_type_inside_abi, "${stype} is not an integer type", ("stype",stype));
151152
if( boost::starts_with(stype, "uint") ) {
152153
return boost::lexical_cast<int>(stype.substr(4));
153154
} else {
@@ -178,7 +179,7 @@ namespace eosio { namespace chain {
178179
}
179180

180181
bool abi_serializer::_is_type(const type_name& rtype, size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time)const {
181-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
182+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
182183
if( ++recursion_depth > max_recursion_depth) return false;
183184
auto type = fundamental_type(rtype);
184185
if( built_in_types.find(type) != built_in_types.end() ) return true;
@@ -189,7 +190,7 @@ namespace eosio { namespace chain {
189190

190191
const struct_def& abi_serializer::get_struct(const type_name& type)const {
191192
auto itr = structs.find(resolve_type(type) );
192-
FC_ASSERT( itr != structs.end(), "Unknown struct ${type}", ("type",type) );
193+
EOS_ASSERT( itr != structs.end(), invalid_type_inside_abi, "Unknown struct ${type}", ("type",type) );
193194
return itr->second;
194195
}
195196

@@ -198,40 +199,40 @@ namespace eosio { namespace chain {
198199
vector<type_name> types_seen{t.first, t.second};
199200
auto itr = typedefs.find(t.second);
200201
while( itr != typedefs.end() ) {
201-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
202-
FC_ASSERT( find(types_seen.begin(), types_seen.end(), itr->second) == types_seen.end(), "Circular reference in type ${type}", ("type",t.first) );
202+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
203+
EOS_ASSERT( find(types_seen.begin(), types_seen.end(), itr->second) == types_seen.end(), abi_circular_def_exception, "Circular reference in type ${type}", ("type",t.first) );
203204
types_seen.emplace_back(itr->second);
204205
itr = typedefs.find(itr->second);
205206
}
206207
} FC_CAPTURE_AND_RETHROW( (t) ) }
207208
for( const auto& t : typedefs ) { try {
208-
FC_ASSERT(_is_type(t.second, 0, deadline, max_serialization_time), "", ("type",t.second) );
209+
EOS_ASSERT(_is_type(t.second, 0, deadline, max_serialization_time), invalid_type_inside_abi, "", ("type",t.second) );
209210
} FC_CAPTURE_AND_RETHROW( (t) ) }
210211
for( const auto& s : structs ) { try {
211212
if( s.second.base != type_name() ) {
212213
struct_def current = s.second;
213214
vector<type_name> types_seen{current.name};
214215
while( current.base != type_name() ) {
215-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
216+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
216217
const auto& base = get_struct(current.base); //<-- force struct to inherit from another struct
217-
FC_ASSERT( find(types_seen.begin(), types_seen.end(), base.name) == types_seen.end(), "Circular reference in struct ${type}", ("type",s.second.name) );
218+
EOS_ASSERT( find(types_seen.begin(), types_seen.end(), base.name) == types_seen.end(), abi_circular_def_exception, "Circular reference in struct ${type}", ("type",s.second.name) );
218219
types_seen.emplace_back(base.name);
219220
current = base;
220221
}
221222
}
222223
for( const auto& field : s.second.fields ) { try {
223-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
224-
FC_ASSERT(_is_type(field.type, 0, deadline, max_serialization_time) );
224+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
225+
EOS_ASSERT(_is_type(field.type, 0, deadline, max_serialization_time), invalid_type_inside_abi, "", ("type",field.type) );
225226
} FC_CAPTURE_AND_RETHROW( (field) ) }
226227
} FC_CAPTURE_AND_RETHROW( (s) ) }
227228
for( const auto& a : actions ) { try {
228-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
229-
FC_ASSERT(_is_type(a.second, 0, deadline, max_serialization_time), "", ("type",a.second) );
229+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
230+
EOS_ASSERT(_is_type(a.second, 0, deadline, max_serialization_time), invalid_type_inside_abi, "", ("type",a.second) );
230231
} FC_CAPTURE_AND_RETHROW( (a) ) }
231232

232233
for( const auto& t : tables ) { try {
233-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
234-
FC_ASSERT(_is_type(t.second, 0, deadline, max_serialization_time), "", ("type",t.second) );
234+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
235+
EOS_ASSERT(_is_type(t.second, 0, deadline, max_serialization_time), invalid_type_inside_abi, "", ("type",t.second) );
235236
} FC_CAPTURE_AND_RETHROW( (t) ) }
236237
}
237238

@@ -251,8 +252,8 @@ namespace eosio { namespace chain {
251252
fc::mutable_variant_object& obj, size_t recursion_depth,
252253
const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
253254
{
254-
FC_ASSERT( ++recursion_depth < max_recursion_depth, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
255-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
255+
EOS_ASSERT( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
256+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
256257
const auto& st = get_struct(type);
257258
if( st.base != type_name() ) {
258259
_binary_to_variant(resolve_type(st.base), stream, obj, recursion_depth, deadline, max_serialization_time);
@@ -265,8 +266,8 @@ namespace eosio { namespace chain {
265266
fc::variant abi_serializer::_binary_to_variant( const type_name& type, fc::datastream<const char *>& stream,
266267
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
267268
{
268-
FC_ASSERT( ++recursion_depth < max_recursion_depth, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
269-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
269+
EOS_ASSERT( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
270+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
270271
type_name rtype = resolve_type(type);
271272
auto ftype = fundamental_type(rtype);
272273
auto btype = built_in_types.find(ftype );
@@ -279,12 +280,13 @@ namespace eosio { namespace chain {
279280
vector<fc::variant> vars;
280281
for( decltype(size.value) i = 0; i < size; ++i ) {
281282
auto v = _binary_to_variant(ftype, stream, recursion_depth, deadline, max_serialization_time);
282-
FC_ASSERT( !v.is_null(), "Invalid packed array" );
283+
EOS_ASSERT( !v.is_null(), unpack_exception, "Invalid packed array" );
283284
vars.emplace_back(std::move(v));
284285
}
285-
FC_ASSERT( vars.size() == size.value,
286-
"packed size does not match unpacked array size, packed size ${p} actual size ${a}",
287-
("p", size)("a", vars.size()) );
286+
EOS_ASSERT( vars.size() == size.value,
287+
unpack_exception,
288+
"packed size does not match unpacked array size, packed size ${p} actual size ${a}",
289+
("p", size)("a", vars.size()) );
288290
return fc::variant( std::move(vars) );
289291
} else if ( is_optional(rtype) ) {
290292
char flag;
@@ -294,24 +296,24 @@ namespace eosio { namespace chain {
294296

295297
fc::mutable_variant_object mvo;
296298
_binary_to_variant(rtype, stream, mvo, recursion_depth, deadline, max_serialization_time);
297-
FC_ASSERT( mvo.size() > 0, "Unable to unpack stream ${type}", ("type", type) );
299+
EOS_ASSERT( mvo.size() > 0, unpack_exception, "Unable to unpack stream ${type}", ("type", type) );
298300
return fc::variant( std::move(mvo) );
299301
}
300302

301303
fc::variant abi_serializer::_binary_to_variant( const type_name& type, const bytes& binary,
302304
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
303305
{
304-
FC_ASSERT( ++recursion_depth < max_recursion_depth, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
305-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
306+
EOS_ASSERT( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
307+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
306308
fc::datastream<const char*> ds( binary.data(), binary.size() );
307309
return _binary_to_variant(type, ds, recursion_depth, deadline, max_serialization_time);
308310
}
309311

310312
void abi_serializer::_variant_to_binary( const type_name& type, const fc::variant& var, fc::datastream<char *>& ds,
311313
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
312314
{ try {
313-
FC_ASSERT( ++recursion_depth < max_recursion_depth, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
314-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
315+
EOS_ASSERT( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
316+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
315317
auto rtype = resolve_type(type);
316318

317319
auto btype = built_in_types.find(fundamental_type(rtype));
@@ -339,14 +341,12 @@ namespace eosio { namespace chain {
339341
else {
340342
_variant_to_binary(field.type, fc::variant(), ds, recursion_depth, deadline, max_serialization_time);
341343
/// TODO: default construct field and write it out
342-
FC_THROW( "Missing '${f}' in variant object", ("f",field.name) );
344+
EOS_THROW( pack_exception, "Missing '${f}' in variant object", ("f",field.name) );
343345
}
344346
}
345347
} else if( var.is_array() ) {
346348
const auto& va = var.get_array();
347-
348-
FC_ASSERT( st.base == type_name(), "support for base class as array not yet implemented" );
349-
349+
EOS_ASSERT( st.base == type_name(), invalid_type_inside_abi, "support for base class as array not yet implemented" );
350350
uint32_t i = 0;
351351
if (va.size() > 0) {
352352
for( const auto& field : st.fields ) {
@@ -364,8 +364,8 @@ namespace eosio { namespace chain {
364364
bytes abi_serializer::_variant_to_binary( const type_name& type, const fc::variant& var,
365365
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
366366
{ try {
367-
FC_ASSERT( ++recursion_depth < max_recursion_depth, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
368-
FC_ASSERT( fc::time_point::now() < deadline, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
367+
EOS_ASSERT( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception, "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) );
368+
EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, "serialization time limit ${t}us exceeded", ("t", max_serialization_time) );
369369
if( !_is_type(type, recursion_depth, deadline, max_serialization_time) ) {
370370
return var.as<bytes>();
371371
}

0 commit comments

Comments
 (0)