Avoid nesting in parsing/error handling code

This commit is contained in:
Martchus 2021-02-02 15:05:45 +01:00
parent 82d0834e75
commit 16c1d96a28
1 changed files with 105 additions and 105 deletions

View File

@ -840,7 +840,6 @@ bool TagEditorWidget::startParsing(const QString &path, bool forceRefresh)
// define function to parse the file // define function to parse the file
const auto startThread = [this, &diag] { const auto startThread = [this, &diag] {
char result; char result;
try { // credits for this nesting go to GCC regression 66145
try { try {
// try to open with write access // try to open with write access
try { try {
@ -859,8 +858,7 @@ bool TagEditorWidget::startParsing(const QString &path, bool forceRefresh)
// the file could not be opened because an IO error occured // the file could not be opened because an IO error occured
m_fileInfo.close(); // ensure file is closed m_fileInfo.close(); // ensure file is closed
result = IoError; result = IoError;
} } catch (const std::exception &e) {
} catch (const exception &e) {
diag.emplace_back(TagParser::DiagLevel::Critical, argsToString("Something completely unexpected happened: ", +e.what()), "parsing"); diag.emplace_back(TagParser::DiagLevel::Critical, argsToString("Something completely unexpected happened: ", +e.what()), "parsing");
result = FatalParsingError; result = FatalParsingError;
} catch (...) { } catch (...) {
@ -904,6 +902,7 @@ bool TagEditorWidget::reparseFile()
*/ */
void TagEditorWidget::showFile(char result) void TagEditorWidget::showFile(char result)
{ {
// handle IO errors
if (result == IoError) { if (result == IoError) {
// update status // update status
updateFileStatusStatus(); updateFileStatusStatus();
@ -916,7 +915,9 @@ void TagEditorWidget::showFile(char result)
msgBox->setInformativeText(tr("Opening file: ") + m_currentPath); msgBox->setInformativeText(tr("Opening file: ") + m_currentPath);
msgBox->show(); msgBox->show();
emit statusMessage(statusMsg); emit statusMessage(statusMsg);
} else { return;
}
// load existing tags // load existing tags
m_tags.clear(); m_tags.clear();
m_fileInfo.tags(m_tags); m_fileInfo.tags(m_tags);
@ -1006,7 +1007,6 @@ void TagEditorWidget::showFile(char result)
emit statusMessage(tr("The file %1 has been opened.").arg(m_currentPath)); emit statusMessage(tr("The file %1 has been opened.").arg(m_currentPath));
emit fileShown(); emit fileShown();
} }
}
/*! /*!
* \brief Invokes saving the current file and - if saving was successful loading the next file. * \brief Invokes saving the current file and - if saving was successful loading the next file.