Skip to content

Commit

Permalink
Stop using perror(), use strerror(errno) instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Nov 29, 2017
1 parent a144940 commit 9a3d29d
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 31 deletions.
9 changes: 7 additions & 2 deletions source/src_common/common/command_executer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
#include "common/argc_argv_faker.hpp"
#include "common/exception/runtime_error_exception.hpp"

#include <iostream>
#include <sys/wait.h>

using namespace cath;
using namespace cath::common;
using namespace std;

using boost::filesystem::path;
using boost::range::join;
using std::cerr;
using std::strerror;

/// \brief Execute a system command, allowing searching within PATH but not using the shell to process the command
///
Expand All @@ -57,7 +59,10 @@ bool command_executer::execute(const path &arg_command, ///< TODOCUMENT
}
else if (pid == 0) {
if ( execvp( arg_command.string().c_str(), arguments_faker.get_argv() ) == -1) {
perror( ("Error executing " + arg_command.string()).c_str() );
cerr << "Error executing "
<< arg_command.string()
<< " : "
<< strerror( errno );
_exit(127);
}
}
Expand Down
41 changes: 31 additions & 10 deletions source/uni/alignment/io/alignment_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ using namespace cath::align;
using namespace cath::chop;
using namespace cath::common;
using namespace cath::file;
using namespace std;

using boost::adaptors::transformed;
using boost::algorithm::icontains;
Expand All @@ -82,6 +81,17 @@ using boost::none;
using boost::numeric_cast;
using boost::to_upper;
using boost::trim;
using std::cerr;
using std::endl;
using std::flush;
using std::ifstream;
using std::ios;
using std::istream;
using std::ofstream;
using std::ostream;
using std::ostringstream;
using std::strerror;
using std::string;

const double MIN_FRAC_OF_PDB_RESIDUES_IN_SEQ( 0.7 );

Expand Down Expand Up @@ -429,9 +439,12 @@ alignment cath::align::read_alignment_from_cath_cora_legacy_format(istream
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message(string("Cannot read CORA legacy alignment file [") + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot read CORA legacy alignment file ["s
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down Expand Up @@ -753,9 +766,12 @@ alignment cath::align::read_alignment_from_fasta(istream &arg_i
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message(string("Cannot read FASTA legacy alignment file [") + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot read FASTA legacy alignment file ["s
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down Expand Up @@ -871,9 +887,14 @@ void cath::align::write_alignment_as_cath_ssap_legacy_format(const path
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message("Cannot output alignment to file \"" + arg_output_file.string() + "\" [" + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot output alignment to file \""
+ arg_output_file.string()
+ "\" ["
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down
23 changes: 17 additions & 6 deletions source/uni/file/pdb/pdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ using std::pair;
using std::right;
using std::set;
using std::setw;
using std::strerror;
using std::string;
using std::stringstream;
using std::tuple;
Expand Down Expand Up @@ -118,9 +119,14 @@ void pdb::read_file(const path &arg_filename ///< TODOCUMENT
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message("Cannot read PDB file \"" + arg_filename.string() + "\" [" + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot read PDB file \""
+ arg_filename.string()
+ "\" ["
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand All @@ -144,9 +150,14 @@ void pdb::append_to_file(const path &arg_filename ///< TODOCUMENT
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message("Cannot append to PDB file \"" + arg_filename.string() + "\" [" + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot append to PDB file \""
+ arg_filename.string()
+ "\" ["
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down
51 changes: 38 additions & 13 deletions source/uni/superposition/io/superposition_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ using namespace cath::file;
using namespace cath::geom;
using namespace cath::sup;
using namespace cath::sup::detail;
using namespace std;

using boost::adaptors::map_values;
using boost::algorithm::any_of;
using boost::filesystem::path;
using boost::irange;
using boost::property_tree::ptree;
using std::fixed;
using std::ofstream;
using std::ostream;
using std::setprecision;
using std::strerror;
using std::string;

const string superposition_io_consts::ENTRIES_KEY = "entries";
const string superposition_io_consts::NAME_KEY = "name";
Expand Down Expand Up @@ -142,9 +147,14 @@ void cath::sup::write_xml_sup_filename(const superposition &arg_superposition,
throw;
}
catch (const std::exception & ex) {
const string error_message("Cannot write XML superposition file \"" + arg_filename.string() + "\" [" + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot write XML superposition file \""
+ arg_filename.string()
+ "\" ["
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down Expand Up @@ -284,9 +294,14 @@ exit
// }
// // Catch any I/O exceptions
// catch (const std::exception &ex) {
// const string error_message("Cannot write superposition to file \"" + arg_filename.string() + "\" [" + ex.what() + "] ");
// perror(error_message.c_str());
// BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
// BOOST_THROW_EXCEPTION(runtime_error_exception(
// "Cannot write superposition to file \""
// + arg_filename.string()
// + "\" ["
// + ex.what()
// + "] : "
// + strerror( errno )
// ));
// };
//}

Expand Down Expand Up @@ -326,9 +341,14 @@ void cath::sup::write_superposed_pdb_to_file(const superposition &arg_sup
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message("Cannot write superposition to file \"" + arg_filename.string() + "\" [" + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot write superposition to file \""
+ arg_filename.string()
+ "\" ["
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down Expand Up @@ -368,9 +388,14 @@ void cath::sup::write_superposed_pdb_to_file(const superposition &arg_s
}
// Catch any I/O exceptions
catch (const std::exception &ex) {
const string error_message("Cannot write superposition to file \"" + arg_filename.string() + "\" [" + ex.what() + "] ");
perror(error_message.c_str());
BOOST_THROW_EXCEPTION(runtime_error_exception(error_message));
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Cannot write superposition to file \""
+ arg_filename.string()
+ "\" ["
+ ex.what()
+ "] : "
+ strerror( errno )
));
};
}

Expand Down

1 comment on commit 9a3d29d

@tonyelewis
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were later tweaked in 0739f47.

Please sign in to comment.