Skip to content

Commit a758b68

Browse files
massjhunsaker
authored andcommitted
pyth: Print error and return 1 on mapping key failure.
Previously, pyth would return a 0 exit code but not return any data. This could happen if the mapping key is missing or invalid. Also, only try updating the price::pub_idx_ if the manager actually has a publish public key. This was causing a crash when running the tools without a publish keypair. This should be valid for running in monitoring / consuming modes.
1 parent 9cd149d commit a758b68

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pc/request.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,10 +2145,12 @@ void price::update_pub()
21452145
// update publishing index
21462146
pub_idx_ = (unsigned)-1;
21472147
pub_key *pkey = get_manager()->get_publish_pub_key();
2148-
for( unsigned i=0; i != pptr_->num_; ++i ) {
2149-
if ( pc_pub_key_equal( &pptr_->comp_[i].pub_, (pc_pub_key_t*)pkey ) ) {
2150-
pub_idx_ = i;
2151-
break;
2148+
if ( pkey ) {
2149+
for( unsigned i=0; i != pptr_->num_; ++i ) {
2150+
if ( pc_pub_key_equal( &pptr_->comp_[i].pub_, (pc_pub_key_t*)pkey ) ) {
2151+
pub_idx_ = i;
2152+
break;
2153+
}
21522154
}
21532155
}
21542156
}

pcapps/pyth.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,11 @@ int on_get_product_list( int argc, char **argv )
10141014
std::cerr << "pyth: " << mgr.get_err_msg() << std::endl;
10151015
return 1;
10161016
}
1017+
if ( !mgr.has_status( PC_PYTH_HAS_MAPPING ) ) {
1018+
std::cerr << "pyth: mapping not ready, check mapping key ["
1019+
<< mgr.get_mapping_pub_key_file() << "]" << std::endl;
1020+
return 1;
1021+
}
10171022
// list key/symbol pairs
10181023
if ( !do_json ) {
10191024
std::string astr;
@@ -1206,6 +1211,11 @@ int on_get_product( int argc, char **argv )
12061211
std::cerr << "pyth: " << mgr.get_err_msg() << std::endl;
12071212
return 1;
12081213
}
1214+
if ( !mgr.has_status( PC_PYTH_HAS_MAPPING ) ) {
1215+
std::cerr << "pyth: mapping not ready, check mapping key ["
1216+
<< mgr.get_mapping_pub_key_file() << "]" << std::endl;
1217+
return 1;
1218+
}
12091219
// get product and serialize to stdout
12101220
product *prod = mgr.get_product( pub );
12111221
if ( !prod ) {

0 commit comments

Comments
 (0)