Handle unexpected exceptions when parsing/making

* Don't just ignore exception (previous behavior)
* Add critical notification
* Show results, though error (to ease debugging)
This commit is contained in:
Martchus 2016-11-13 22:57:02 +01:00
parent 89d2da0191
commit 1924c1d804
2 changed files with 36 additions and 20 deletions

View File

@ -317,9 +317,9 @@ uint64 parseUInt64(const Argument &arg, uint64 defaultValue)
if(arg.isPresent()) {
try {
if(*arg.values().front() == '0' && *(arg.values().front() + 1) == 'x') {
return stringToNumber<decltype(parseUInt64(arg, defaultValue))>(arg.values().front() + 2, 16);
return stringToNumber<uint64>(arg.values().front() + 2, 16);
} else {
return stringToNumber<decltype(parseUInt64(arg, defaultValue))>(arg.values().front());
return stringToNumber<uint64>(arg.values().front());
}
} catch(const ConversionException &) {
cerr << "Warning: The specified value \"" << arg.values().front() << "\" is no valid unsigned integer and will be ignored." << endl;

View File

@ -752,26 +752,34 @@ bool TagEditorWidget::startParsing(const QString &path, bool forceRefresh)
auto startThread = [this] {
m_fileOperationMutex.lock();
char result;
try {
try { // credits for this nesting go to GCC regression 66145
try {
// try to open with write access
m_fileInfo.reopen(false);
try {
// try to open with write access
m_fileInfo.reopen(false);
} catch(...) {
::IoUtilities::catchIoFailure();
// try to open read-only if opening with write access failed
m_fileInfo.reopen(true);
}
m_fileInfo.setForceFullParse(Settings::values().editor.forceFullParse);
m_fileInfo.parseEverything();
result = ParsingSuccessful;
} catch(const Failure &) {
// the file has been opened; parsing notifications will be shown in the info box
result = FatalParsingError;
} catch(...) {
::IoUtilities::catchIoFailure();
// try to open read-only if opening with write access failed
m_fileInfo.reopen(true);
// the file could not be opened because an IO error occured
m_fileInfo.close(); // ensure file is closed
result = IoError;
}
m_fileInfo.setForceFullParse(Settings::values().editor.forceFullParse);
m_fileInfo.parseEverything();
result = ParsingSuccessful;
} catch(const Failure &) {
// the file has been opened; parsing notifications will be shown in the info box
} catch(const exception &e) {
m_fileInfo.addNotification(Media::NotificationType::Critical, string("Something completely unexpected happened: ") + e.what(), "parsing");
result = FatalParsingError;
} catch(...) {
::IoUtilities::catchIoFailure();
// the file could not be opened because an IO error occured
m_fileInfo.close(); // ensure file is closed
result = IoError;
m_fileInfo.addNotification(Media::NotificationType::Critical, "Something completely unexpected happened", "parsing");
result = FatalParsingError;
}
m_fileInfo.unregisterAllCallbacks();
QMetaObject::invokeMethod(this, "showFile", Qt::QueuedConnection, Q_ARG(char, result));
@ -1080,12 +1088,20 @@ bool TagEditorWidget::startSaving()
m_fileOperationMutex.lock();
bool processingError = false, ioError = false;
try {
m_fileInfo.applyChanges();
} catch(const Failure &) {
try {
m_fileInfo.applyChanges();
} catch(const Failure &) {
processingError = true;
} catch(...) {
::IoUtilities::catchIoFailure();
ioError = true;
}
} catch(const exception &e) {
m_fileInfo.addNotification(Media::NotificationType::Critical, string("Something completely unexpected happened: ") + e.what(), "making");
processingError = true;
} catch(...) {
::IoUtilities::catchIoFailure();
ioError = true;
m_fileInfo.addNotification(Media::NotificationType::Critical, "Something completely unexpected happened", "making");
processingError = true;
}
m_fileInfo.unregisterAllCallbacks();
QMetaObject::invokeMethod(this, "showSavingResult", Qt::QueuedConnection, Q_ARG(bool, processingError), Q_ARG(bool, ioError));