From 3b57d5a258bb5e9bddb35d862da8a5b292ee5d3e Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 21 Sep 2022 10:48:13 -0500 Subject: [PATCH 1/7] GH-139 Update cleos to return an error code on failed trx processing similar to before --return-failure-trace was added. --- .../eosio/chain_plugin/chain_plugin.hpp | 4 +- programs/cleos/main.cpp | 40 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index 9f5a523a12..9b408e70e0 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -441,7 +441,7 @@ class read_only { get_scheduled_transactions_result get_scheduled_transactions( const get_scheduled_transactions_params& params ) const; struct compute_transaction_results { chain::transaction_id_type transaction_id; - fc::variant processed; + fc::variant processed; // "processed" is expected JSON for trxs in cleos }; struct compute_transaction_params { @@ -666,7 +666,7 @@ class read_write { using push_transaction_params = fc::variant_object; struct push_transaction_results { chain::transaction_id_type transaction_id; - fc::variant processed; + fc::variant processed; // "processed" is expected JSON for trxs in cleos }; void push_transaction(const push_transaction_params& params, chain::plugin_interface::next_function next); diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 178109a0b5..896eaf33f4 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -188,6 +188,7 @@ bool print_request = false; bool print_response = false; bool no_auto_keosd = false; bool verbose = false; +int return_code = 0; uint8_t tx_max_cpu_usage = 0; uint32_t tx_max_net_usage = 0; @@ -538,6 +539,31 @@ void print_action_tree( const fc::variant& action ) { } } +int get_return_code( const fc::variant& result ) { + // if a trx with a processed, then check to see if it failed execution for return value + int r = 0; + if (result.is_object() && result.get_object().contains("processed")) { + const auto& processed = result["processed"]; + if( processed.get_object().contains( "except" ) ) { + try { + auto soft_except = processed["except"].as>(); + if( soft_except ) { + auto code = soft_except->code(); + if( code > std::numeric_limits::max() ) { + r = 1; + } else { + r = static_cast( code ); + } + } + if( r == 0 ) r = 1; + } catch( ... ) { + r = 1; + } + } + } + return r; +} + void print_result( const fc::variant& result ) { try { if (result.is_object() && result.get_object().contains("processed")) { const auto& processed = result["processed"]; @@ -600,6 +626,7 @@ void send_actions(std::vector&& actions, packed_transaction::comp out << jsonstr; out.close(); } + return_code = get_return_code( result ); if( tx_print_json ) { if (jsonstr.length() == 0) { jsonstr = fc::json::to_pretty_string( result ); @@ -624,6 +651,7 @@ void send_transaction( signed_transaction& trx, packed_transaction::compression_ out << jsonstr; out.close(); } + return_code = get_return_code( result ); if( tx_print_json ) { if (jsonstr.length() == 0) { jsonstr = fc::json::to_pretty_string( result ); @@ -4136,14 +4164,16 @@ int main( int argc, char** argv ) { } return 1; } catch ( const std::bad_alloc& ) { - elog("bad alloc"); + elog("bad alloc"); + return 1; } catch( const boost::interprocess::bad_alloc& ) { - elog("bad alloc"); + elog("bad alloc"); + return 1; } catch (const fc::exception& e) { - return handle_error(e); + return handle_error(e); } catch (const std::exception& e) { - return handle_error(fc::std_exception_wrapper::from_current_exception(e)); + return handle_error(fc::std_exception_wrapper::from_current_exception(e)); } - return 0; + return return_code; } From ea7e3a34ea6f2497320070112f025e264f5f0c1c Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 21 Sep 2022 13:12:55 -0500 Subject: [PATCH 2/7] GH-139 Fix for setting error code when no error actually happened. --- programs/cleos/main.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 896eaf33f4..572c2a6c5b 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -545,19 +545,22 @@ int get_return_code( const fc::variant& result ) { if (result.is_object() && result.get_object().contains("processed")) { const auto& processed = result["processed"]; if( processed.get_object().contains( "except" ) ) { - try { - auto soft_except = processed["except"].as>(); - if( soft_except ) { - auto code = soft_except->code(); - if( code > std::numeric_limits::max() ) { - r = 1; - } else { - r = static_cast( code ); + const auto& except = processed["except"]; + if( except.is_object() ) { + try { + auto soft_except = except.as>(); + if( soft_except ) { + auto code = soft_except->code(); + if( code > std::numeric_limits::max() ) { + r = 1; + } else { + r = static_cast( code ); + } + if( r == 0 ) r = 1; } + } catch( ... ) { + r = 1; } - if( r == 0 ) r = 1; - } catch( ... ) { - r = 1; } } } From 04a831e77ab4c935cedc82ab93683ef150bfb93f Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 21 Sep 2022 14:48:59 -0500 Subject: [PATCH 3/7] GH-139 On cleos failure capture both stderr and stdout in output as some tests are expecting to find errors in the trace. --- tests/Node.py | 2 +- tests/prod_preactivation_test.py | 5 +++-- tests/testUtils.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Node.py b/tests/Node.py index bc133bedd1..dbc9f50f60 100644 --- a/tests/Node.py +++ b/tests/Node.py @@ -776,7 +776,7 @@ def publishContract(self, account, contractDir, wasmFile, abiFile, waitForTransB if shouldFail: if trans["processed"]["except"] != None: retMap={} - retMap["returncode"]=0 + retMap["returncode"]=1 retMap["cmd"]=cmd retMap["output"]=bytes(str(trans),'utf-8') return retMap diff --git a/tests/prod_preactivation_test.py b/tests/prod_preactivation_test.py index 406366dacd..2930caf46f 100755 --- a/tests/prod_preactivation_test.py +++ b/tests/prod_preactivation_test.py @@ -112,8 +112,9 @@ Print("publish a new bios contract %s should fails because env.is_feature_activated unresolveable" % (contractDir)) retMap = node0.publishContract("eosio", contractDir, wasmFile, abiFile, True, shouldFail=True) - if retMap["output"].decode("utf-8").find("unresolveable") < 0: - errorExit("bios contract not result in expected unresolveable error") + outPut = retMap["output"].decode("utf-8") + if outPut.find("unresolveable") < 0: + errorExit(f"bios contract not result in expected unresolveable error: {outPut}") secwait = 30 Print("Wait for node 1 to produce...") diff --git a/tests/testUtils.py b/tests/testUtils.py index e4fa9ec599..8af001722e 100755 --- a/tests/testUtils.py +++ b/tests/testUtils.py @@ -205,7 +205,8 @@ def checkDelayedOutput(popen, cmd, ignoreError=False): Utils.checkOutputFileWrite(start, cmd, output, error) if popen.returncode != 0 and not ignoreError: Utils.Print("ERROR: %s" % error) - raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=error) + # for now just include both stderr and stdout in output + raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=error+" "+output) return output.decode("utf-8") @staticmethod From 89466843df10169cf3e098e8a1c8e68834d56349 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 21 Sep 2022 15:06:54 -0500 Subject: [PATCH 4/7] GH-139 stdout,stderr are byte arrays --- tests/testUtils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testUtils.py b/tests/testUtils.py index 8af001722e..55c225d530 100755 --- a/tests/testUtils.py +++ b/tests/testUtils.py @@ -205,8 +205,8 @@ def checkDelayedOutput(popen, cmd, ignoreError=False): Utils.checkOutputFileWrite(start, cmd, output, error) if popen.returncode != 0 and not ignoreError: Utils.Print("ERROR: %s" % error) - # for now just include both stderr and stdout in output - raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=error+" "+output) + # for now just include both stderr and stdout in output, python 3.5+ supports both a stdout and stderr attributes + raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=error+bytes(" ", 'utf-8')+output) return output.decode("utf-8") @staticmethod From 8282cd5a90790fc4bede127b486ad876686a7834 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 21 Sep 2022 22:48:38 -0500 Subject: [PATCH 5/7] GH-139 verify is an object before get_object --- programs/cleos/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 572c2a6c5b..3781f91bc7 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -544,7 +544,7 @@ int get_return_code( const fc::variant& result ) { int r = 0; if (result.is_object() && result.get_object().contains("processed")) { const auto& processed = result["processed"]; - if( processed.get_object().contains( "except" ) ) { + if( processed.is_object() && processed.get_object().contains( "except" ) ) { const auto& except = processed["except"]; if( except.is_object() ) { try { From ced38878781ee8c45ab077b1e74532599a828fea Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 22 Sep 2022 07:01:05 -0500 Subject: [PATCH 6/7] GH-139 remove unneeded optional --- programs/cleos/main.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 3781f91bc7..9f41194956 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -548,16 +548,14 @@ int get_return_code( const fc::variant& result ) { const auto& except = processed["except"]; if( except.is_object() ) { try { - auto soft_except = except.as>(); - if( soft_except ) { - auto code = soft_except->code(); - if( code > std::numeric_limits::max() ) { - r = 1; - } else { - r = static_cast( code ); - } - if( r == 0 ) r = 1; + auto soft_except = except.as(); + auto code = soft_except.code(); + if( code > std::numeric_limits::max() ) { + r = 1; + } else { + r = static_cast( code ); } + if( r == 0 ) r = 1; } catch( ... ) { r = 1; } From f12be2fdec830af97d831f866fde879cf49221a6 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 22 Sep 2022 13:14:15 -0500 Subject: [PATCH 7/7] bump version to 3.1.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d8d419c72..64c1d2b7b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set( CXX_STANDARD_REQUIRED ON) set(VERSION_MAJOR 3) set(VERSION_MINOR 1) -set(VERSION_PATCH 0) +set(VERSION_PATCH 1) #set(VERSION_SUFFIX rc4) if(VERSION_SUFFIX)