Skip to content

Commit

Permalink
[swssconfig]: Log errors instead of throwing exception when file open…
Browse files Browse the repository at this point in the history
… fails (sonic-net#277)
  • Loading branch information
Shuotian Cheng authored Aug 8, 2017
1 parent 9b51058 commit 38f2bf3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions swssconfig/swssconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,33 @@ int main(int argc, char **argv)
{
SWSS_LOG_NOTICE("Loading config from JSON file:%s...", i.c_str());

ifstream fs;
vector<KeyOpFieldsValuesTuple> db_items;
try
{
fs.open(i, fstream::in);
ifstream fs(i);
if (!fs)
{
SWSS_LOG_ERROR("Failed to open file %s", i.c_str());
cerr << "Failed to open file " << i.c_str() << endl;
return EXIT_FAILURE;
}

if (!load_json_db_data(fs, db_items))
{
SWSS_LOG_ERROR("Failed loading data from JSON file:%s", i.c_str());
SWSS_LOG_ERROR("Failed loading data from JSON file %s", i.c_str());
return EXIT_FAILURE;
}

if (!write_db_data(db_items))
{
SWSS_LOG_ERROR("Failed applying data from JSON file:%s", i.c_str());
SWSS_LOG_ERROR("Failed applying data from JSON file %s", i.c_str());
return EXIT_FAILURE;
}
}
catch(const exception &e)
{
SWSS_LOG_ERROR("Exception caught:%s", e.what());
cout << "Exception caught:" << e.what() << endl;
SWSS_LOG_ERROR("Exception caught: %s", e.what());
cout << "Exception caught: " << e.what() << endl;
return EXIT_FAILURE;
}
}
Expand Down

0 comments on commit 38f2bf3

Please sign in to comment.