diff --git a/src/core/buffer/buffer.cpp b/src/core/buffer/buffer.cpp index 624e884b..283a62b4 100644 --- a/src/core/buffer/buffer.cpp +++ b/src/core/buffer/buffer.cpp @@ -209,7 +209,13 @@ Buffer::OperationCode Buffer::save(bool p_force) return OperationCode::FileChangedOutside; } - m_provider->write(m_content); + try { + m_provider->write(m_content); + } catch (Exception &p_e) { + qWarning() << "failed to write the buffer content" << getPath(); + return OperationCode::Failed; + } + setModified(false); m_state &= ~(StateFlag::FileMissingOnDisk | StateFlag::FileChangedOutside); } @@ -312,11 +318,17 @@ void Buffer::autoSave() return; case EditorConfig::AutoSavePolicy::AutoSave: - save(false); + if (save(false) != OperationCode::Success) { + qWarning() << "AutoSave failed to save buffer, retry later"; + } break; case EditorConfig::AutoSavePolicy::BackupFile: - writeBackupFile(); + try { + writeBackupFile(); + } catch (Exception &p_e) { + qWarning() << "AutoSave failed to write backup file, retry later"; + } break; } } diff --git a/src/core/notebookmgr.cpp b/src/core/notebookmgr.cpp index bc194348..b489a8ff 100644 --- a/src/core/notebookmgr.cpp +++ b/src/core/notebookmgr.cpp @@ -102,7 +102,7 @@ QSharedPointer NotebookMgr::createNotebookBackend(const QStrin return factory->createNotebookBackend(p_rootFolderPath); } else { Exception::throwOne(Exception::Type::InvalidArgument, - QString("fail to find notebook backend factory %1").arg(p_backendName)); + QString("failed to find notebook backend factory %1").arg(p_backendName)); } return nullptr; @@ -115,7 +115,7 @@ QSharedPointer NotebookMgr::createVersionController(const QS return factory->createVersionController(); } else { Exception::throwOne(Exception::Type::InvalidArgument, - QString("fail to find version controller factory %1").arg(p_controllerName)); + QString("failed to find version controller factory %1").arg(p_controllerName)); } return nullptr; @@ -129,7 +129,7 @@ QSharedPointer NotebookMgr::createNotebookConfigMgr(const QS return factory->createNotebookConfigMgr(p_backend); } else { Exception::throwOne(Exception::Type::InvalidArgument, - QString("fail to find notebook config manager factory %1").arg(p_mgrName)); + QString("failed to find notebook config manager factory %1").arg(p_mgrName)); } return nullptr; @@ -165,7 +165,7 @@ QSharedPointer NotebookMgr::newNotebook(const QSharedPointergetItem(p_parameters->m_type); if (!factory) { Exception::throwOne(Exception::Type::InvalidArgument, - QString("fail to find notebook factory %1").arg(p_parameters->m_type)); + QString("failed to find notebook factory %1").arg(p_parameters->m_type)); } auto notebook = factory->newNotebook(*p_parameters); @@ -225,7 +225,7 @@ void NotebookMgr::readNotebooksFromConfig() auto nb = readNotebookFromConfig(item); addNotebook(nb); } catch (Exception &p_e) { - qCritical("fail to read notebook (%s) from config (%s)", + qCritical("failed to read notebook (%s) from config (%s)", item.m_rootFolderPath.toStdString().c_str(), p_e.what()); } @@ -239,7 +239,7 @@ QSharedPointer NotebookMgr::readNotebookFromConfig(const SessionConfig auto factory = m_notebookServer->getItem(p_item.m_type); if (!factory) { Exception::throwOne(Exception::Type::InvalidArgument, - QString("fail to find notebook factory %1").arg(p_item.m_type)); + QString("failed to find notebook factory %1").arg(p_item.m_type)); } auto backend = createNotebookBackend(p_item.m_backend, p_item.m_rootFolderPath); @@ -304,7 +304,7 @@ void NotebookMgr::closeNotebook(ID p_id) return p_nb->getId() == p_id; }); if (it == m_notebooks.end()) { - qWarning() << "fail to find notebook of given id to close" << p_id; + qWarning() << "failed to find notebook of given id to close" << p_id; return; } @@ -330,7 +330,7 @@ void NotebookMgr::removeNotebook(ID p_id) return p_nb->getId() == p_id; }); if (it == m_notebooks.end()) { - qWarning() << "fail to find notebook of given id to remove" << p_id; + qWarning() << "failed to find notebook of given id to remove" << p_id; return; } @@ -347,7 +347,7 @@ void NotebookMgr::removeNotebook(ID p_id) try { nbToRemove->remove(); } catch (Exception &p_e) { - qWarning() << QString("fail to remove notebook %1 (%2) (%3)").arg(nbToRemove->getName(), + qWarning() << QString("failed to remove notebook %1 (%2) (%3)").arg(nbToRemove->getName(), nbToRemove->getRootFolderPath(), p_e.what()); throw; diff --git a/src/widgets/viewwindow.cpp b/src/widgets/viewwindow.cpp index 14b7b9a7..d59303a6 100644 --- a/src/widgets/viewwindow.cpp +++ b/src/widgets/viewwindow.cpp @@ -812,7 +812,7 @@ bool ViewWindow::save(bool p_force) MessageBoxHelper::notify(MessageBoxHelper::Warning, tr("Failed to save note (%1).").arg(m_buffer->getName()), tr("Please check the file (%1) and try it again.").arg(m_buffer->getPath()), - "", + tr("Maybe the file is occupied by another service temporarily."), this); return false; }