diff --git a/logdoctor/tools/craphelp/craphelp.cpp b/logdoctor/tools/craphelp/craphelp.cpp index 5638b529..442eb940 100644 --- a/logdoctor/tools/craphelp/craphelp.cpp +++ b/logdoctor/tools/craphelp/craphelp.cpp @@ -66,8 +66,8 @@ const std::unordered_map Craphelp::getColorScheme( const i {"link", "#ff85a1"} }; default: - // wrong - throw GenericException( "Unexpected ColorScheme ID: "+std::to_string( scheme_id ) ); + // wrong, shouldn't be here + throw GenericException( "Unexpected ColorScheme ID: "+std::to_string( scheme_id ), true ); // leave un-catched } } diff --git a/logdoctor/tools/craplog/modules/hash.cpp b/logdoctor/tools/craplog/modules/hash.cpp index a92428a0..5c1f6c65 100644 --- a/logdoctor/tools/craplog/modules/hash.cpp +++ b/logdoctor/tools/craplog/modules/hash.cpp @@ -77,7 +77,7 @@ std::string HashOps::digestFile( const std::string& file_path ) // try reading as gzip compressed file GZutils::readFile( file_path, content ); - } catch (GenericException& e) { + } catch (const GenericException& e) { // failed closing file pointer throw e; @@ -89,17 +89,27 @@ std::string HashOps::digestFile( const std::string& file_path ) IOutils::readFile( file_path, content ); } - } catch (GenericException& err) { - // failed closing - throw err; + // re-catched in craplog + } catch (const GenericException) { + // failed closing gzip file pointer + throw GenericException( QString("%1:\n%2").arg( + DialogSec::tr("An error accured while reading the gzipped file"), + QString::fromStdString( file_path ) + ).toStdString() ); } catch (const std::ios_base::failure& err) { - // failed reading - throw err; + // failed reading as text + throw GenericException( QString("%1:\n%2").arg( + DialogSec::tr("An error accured while reading the file"), + QString::fromStdString( file_path ) + ).toStdString() ); } catch (...) { // failed somehow - throw GenericException( "Something failed while handling file" ); + throw GenericException( QString("%1:\n%2").arg( + DialogSec::tr("Something failed while handling the file"), + QString::fromStdString( file_path ) + ).toStdString() ); } SHA256 sha; diff --git a/logdoctor/tools/crapnote/crapnote.cpp b/logdoctor/tools/crapnote/crapnote.cpp index a0005539..147ce725 100644 --- a/logdoctor/tools/crapnote/crapnote.cpp +++ b/logdoctor/tools/crapnote/crapnote.cpp @@ -53,7 +53,7 @@ void Crapnote::setColorScheme( const int& scheme_id ) break; default: // wrong - throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( scheme_id ) ); + throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( scheme_id ), true ); // leave un-catched } } diff --git a/logdoctor/tools/crapview/modules/query.cpp b/logdoctor/tools/crapview/modules/query.cpp index 390c2096..01d83681 100644 --- a/logdoctor/tools/crapview/modules/query.cpp +++ b/logdoctor/tools/crapview/modules/query.cpp @@ -35,7 +35,7 @@ const int DbQuery::getMinuteGap( const int& minute , const int& gap ) int m = -1; if ( minute < 0 || minute >= 60 ) { // unexpected value - throw GenericException( "Unexpected Minute: "+std::to_string( minute ) ); + throw DateTimeException( "Unexpected Minute: "+std::to_string( minute ) ); } int n = 0; for ( int g=0; g<60; g+=gap ) { @@ -81,7 +81,7 @@ const int DbQuery::getMonthsCount( const QString& from_year, const QString& from to_month_ = ( to_month.size() == 0 ) ? from_month_ : this->getMonthNumber( to_month ) ; } catch (...) { // failed to convert to integers - throw GenericException( "Failed to convert from string to int" ); + throw DateTimeException( "Failed to convert from string to int" ); // leave un-catched } return this->getMonthsCount( from_year_, from_month_, to_year_, to_month_ ); } diff --git a/logdoctor/utilities/io.cpp b/logdoctor/utilities/io.cpp index bcdc0560..87a18519 100644 --- a/logdoctor/utilities/io.cpp +++ b/logdoctor/utilities/io.cpp @@ -138,7 +138,7 @@ void IOutils::randomLines(const std::string& path, std::vector& lin // try reading a gzipped file GZutils::readFile( path, aux ); - } catch (GenericException& e) { + } catch (const GenericException& e) { // failed closing file pointer throw e; @@ -181,21 +181,30 @@ void IOutils::randomLines(const std::string& path, std::vector& lin } } aux_lines.clear(); - } catch (const std::ios_base::failure& err) { + + // re-catched in craplog + } catch (const GenericException) { + // failed closing gzip file pointer + lines.clear(); aux_lines.clear(); + if ( file.is_open() ) { + file.close(); + } + throw GenericException( "An error accured while reading the gzipped file" ); + + } catch (const std::ios_base::failure) { // failed reading - lines.clear(); - aux_lines.clear(); + lines.clear(); aux_lines.clear(); if ( file.is_open() ) { file.close(); } - throw err; + throw GenericException( "An error accured while reading the file" ); + } catch (...) { - lines.clear(); - aux_lines.clear(); + lines.clear(); aux_lines.clear(); if ( file.is_open() ) { file.close(); } - throw std::exception(); // exception catched in Craplog + throw GenericException( "Something failed while handling the file" ); } if ( file.is_open() ) { file.close(); @@ -209,7 +218,7 @@ void IOutils::readFile( const std::string& path , std::string& content ) // read the whole file std::ifstream file; try { - constexpr std::size_t read_size = std::size_t(4096); + /*constexpr std::size_t read_size = std::size_t(4096);*/ file = std::ifstream(path); if ( ! file.is_open() ) { throw std::ios_base::failure( "file is not open" );