Skip to content

Commit a80969d

Browse files
Mariusz-Trelavogel76
authored andcommitted
Issue #668 Not clear enough error messages in some specific cases
1 parent 25efa2e commit a80969d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

libraries/chain/database.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ void database::set_chain_id( const chain_id_type& chain_id )
381381

382382
const witness_object& database::get_witness( const account_name_type& name ) const
383383
{ try {
384-
return get< witness_object, by_name >( name );
384+
const auto* _witness = find_witness( name );
385+
FC_ASSERT( _witness != nullptr, "Witness ${w} doesn't exist", ("w", name) );
386+
return *_witness;
385387
} FC_CAPTURE_AND_RETHROW( (name) ) }
386388

387389
const witness_object* database::find_witness( const account_name_type& name ) const
@@ -404,7 +406,9 @@ bool database::is_treasury( const account_name_type& name )const
404406

405407
const account_object& database::get_account( const account_id_type id )const
406408
{ try {
407-
return get< account_object, by_id >( id );
409+
const auto* _account = find_account( id );
410+
FC_ASSERT( _account != nullptr, "Account with id ${acc} doesn't exist", ("acc", id) );
411+
return *_account;
408412
} FC_CAPTURE_AND_RETHROW( (id) ) }
409413

410414
const account_object* database::find_account( const account_id_type& id )const
@@ -414,7 +418,9 @@ const account_object* database::find_account( const account_id_type& id )const
414418

415419
const account_object& database::get_account( const account_name_type& name )const
416420
{ try {
417-
return get< account_object, by_name >( name );
421+
const auto* _account = find_account( name );
422+
FC_ASSERT( _account != nullptr, "Account ${acc} doesn't exist", ("acc", name) );
423+
return *_account;
418424
} FC_CAPTURE_AND_RETHROW( (name) ) }
419425

420426
const account_object* database::find_account( const account_name_type& name )const
@@ -430,7 +436,9 @@ FC_CAPTURE_AND_RETHROW( (comment_id) )
430436

431437
const comment_object& database::get_comment( const account_id_type& author, const shared_string& permlink )const
432438
{ try {
433-
return get< comment_object, by_permlink >( comment_object::compute_author_and_permlink_hash( author, to_string( permlink ) ) );
439+
const comment_object* comment_ptr = find_comment( author, permlink );
440+
FC_ASSERT( comment_ptr != nullptr, "Comment with `id` ${author} `permlink` ${permlink} not found", (author)(permlink) );
441+
return *comment_ptr;
434442
} FC_CAPTURE_AND_RETHROW( (author)(permlink) ) }
435443

436444
const comment_object* database::find_comment( const account_id_type& author, const shared_string& permlink )const
@@ -456,7 +464,9 @@ const comment_object* database::find_comment( const account_name_type& author, c
456464

457465
const comment_object& database::get_comment( const account_id_type& author, const string& permlink )const
458466
{ try {
459-
return get< comment_object, by_permlink >( comment_object::compute_author_and_permlink_hash( author, permlink ) );
467+
const comment_object* comment_ptr = find_comment( author, permlink );
468+
FC_ASSERT( comment_ptr != nullptr, "Comment with `id` ${author} `permlink` ${permlink} not found", (author)(permlink) );
469+
return *comment_ptr;
460470
} FC_CAPTURE_AND_RETHROW( (author)(permlink) ) }
461471

462472
const comment_object* database::find_comment( const account_id_type& author, const string& permlink )const
@@ -482,7 +492,9 @@ const comment_object* database::find_comment( const account_name_type& author, c
482492

483493
const escrow_object& database::get_escrow( const account_name_type& name, uint32_t escrow_id )const
484494
{ try {
485-
return get< escrow_object, by_from_id >( boost::make_tuple( name, escrow_id ) );
495+
const auto* _escrow = find_escrow( name, escrow_id );
496+
FC_ASSERT( _escrow != nullptr, "Escrow balance with 'name' ${name} 'escrow_id' ${escrow_id} doesn't exist.", (name)(escrow_id) );
497+
return *_escrow;
486498
} FC_CAPTURE_AND_RETHROW( (name)(escrow_id) ) }
487499

488500
const escrow_object* database::find_escrow( const account_name_type& name, uint32_t escrow_id )const
@@ -495,7 +507,10 @@ const limit_order_object& database::get_limit_order( const account_name_type& na
495507
if( !has_hardfork( HIVE_HARDFORK_0_6__127 ) )
496508
orderid = orderid & 0x0000FFFF;
497509

498-
return get< limit_order_object, by_account >( boost::make_tuple( name, orderid ) );
510+
const auto* _limit_order = find_limit_order( name, orderid );
511+
FC_ASSERT( _limit_order != nullptr, "Limit order with 'name' ${name} 'order_id' ${orderid} doesn't exist.", (name)(orderid) );
512+
513+
return *_limit_order;
499514
} FC_CAPTURE_AND_RETHROW( (name)(orderid) ) }
500515

501516
const limit_order_object* database::find_limit_order( const account_name_type& name, uint32_t orderid )const
@@ -508,7 +523,11 @@ const limit_order_object* database::find_limit_order( const account_name_type& n
508523

509524
const savings_withdraw_object& database::get_savings_withdraw( const account_name_type& owner, uint32_t request_id )const
510525
{ try {
511-
return get< savings_withdraw_object, by_from_rid >( boost::make_tuple( owner, request_id ) );
526+
527+
const auto* _savings_withdraw = find_savings_withdraw( owner, request_id );
528+
FC_ASSERT( _savings_withdraw != nullptr, "Savings withdraw for `owner` ${owner} and 'request_id' ${request_id} doesn't exist.", (owner)(request_id) );
529+
530+
return *_savings_withdraw;
512531
} FC_CAPTURE_AND_RETHROW( (owner)(request_id) ) }
513532

514533
const savings_withdraw_object* database::find_savings_withdraw( const account_name_type& owner, uint32_t request_id )const

tests/python/functional/operation_tests/witness_ops_tests/test_feed_publish.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ def test_publish_feed_from_non_witness_account(
3131
# test case 2.1 from https://gitlab.syncad.com/hive/hive/-/issues/633
3232
with pytest.raises(ErrorInResponseError) as error:
3333
alice.feed_publish(base=1000, quote=100)
34-
assert "unknown key" in error.value.error, "Message other than expected."
34+
assert "Witness alice doesn't exist" in error.value.error, "Message other than expected."
3535
alice.check_if_account_has_witness_role(expected_witness_role=False)
3636
alice.assert_rc_current_mana_was_unchanged()

0 commit comments

Comments
 (0)