handle autosave temporary failure

This commit is contained in:
Le Tan 2021-01-01 10:00:24 +08:00
parent d376d1125e
commit 8a1558f4da
3 changed files with 25 additions and 13 deletions

View File

@ -209,7 +209,13 @@ Buffer::OperationCode Buffer::save(bool p_force)
return OperationCode::FileChangedOutside; return OperationCode::FileChangedOutside;
} }
try {
m_provider->write(m_content); m_provider->write(m_content);
} catch (Exception &p_e) {
qWarning() << "failed to write the buffer content" << getPath();
return OperationCode::Failed;
}
setModified(false); setModified(false);
m_state &= ~(StateFlag::FileMissingOnDisk | StateFlag::FileChangedOutside); m_state &= ~(StateFlag::FileMissingOnDisk | StateFlag::FileChangedOutside);
} }
@ -312,11 +318,17 @@ void Buffer::autoSave()
return; return;
case EditorConfig::AutoSavePolicy::AutoSave: case EditorConfig::AutoSavePolicy::AutoSave:
save(false); if (save(false) != OperationCode::Success) {
qWarning() << "AutoSave failed to save buffer, retry later";
}
break; break;
case EditorConfig::AutoSavePolicy::BackupFile: case EditorConfig::AutoSavePolicy::BackupFile:
try {
writeBackupFile(); writeBackupFile();
} catch (Exception &p_e) {
qWarning() << "AutoSave failed to write backup file, retry later";
}
break; break;
} }
} }

View File

@ -102,7 +102,7 @@ QSharedPointer<INotebookBackend> NotebookMgr::createNotebookBackend(const QStrin
return factory->createNotebookBackend(p_rootFolderPath); return factory->createNotebookBackend(p_rootFolderPath);
} else { } else {
Exception::throwOne(Exception::Type::InvalidArgument, 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; return nullptr;
@ -115,7 +115,7 @@ QSharedPointer<IVersionController> NotebookMgr::createVersionController(const QS
return factory->createVersionController(); return factory->createVersionController();
} else { } else {
Exception::throwOne(Exception::Type::InvalidArgument, 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; return nullptr;
@ -129,7 +129,7 @@ QSharedPointer<INotebookConfigMgr> NotebookMgr::createNotebookConfigMgr(const QS
return factory->createNotebookConfigMgr(p_backend); return factory->createNotebookConfigMgr(p_backend);
} else { } else {
Exception::throwOne(Exception::Type::InvalidArgument, 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; return nullptr;
@ -165,7 +165,7 @@ QSharedPointer<Notebook> NotebookMgr::newNotebook(const QSharedPointer<NotebookP
auto factory = m_notebookServer->getItem(p_parameters->m_type); auto factory = m_notebookServer->getItem(p_parameters->m_type);
if (!factory) { if (!factory) {
Exception::throwOne(Exception::Type::InvalidArgument, 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); auto notebook = factory->newNotebook(*p_parameters);
@ -225,7 +225,7 @@ void NotebookMgr::readNotebooksFromConfig()
auto nb = readNotebookFromConfig(item); auto nb = readNotebookFromConfig(item);
addNotebook(nb); addNotebook(nb);
} catch (Exception &p_e) { } 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(), item.m_rootFolderPath.toStdString().c_str(),
p_e.what()); p_e.what());
} }
@ -239,7 +239,7 @@ QSharedPointer<Notebook> NotebookMgr::readNotebookFromConfig(const SessionConfig
auto factory = m_notebookServer->getItem(p_item.m_type); auto factory = m_notebookServer->getItem(p_item.m_type);
if (!factory) { if (!factory) {
Exception::throwOne(Exception::Type::InvalidArgument, 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); 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; return p_nb->getId() == p_id;
}); });
if (it == m_notebooks.end()) { 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; return;
} }
@ -330,7 +330,7 @@ void NotebookMgr::removeNotebook(ID p_id)
return p_nb->getId() == p_id; return p_nb->getId() == p_id;
}); });
if (it == m_notebooks.end()) { 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; return;
} }
@ -347,7 +347,7 @@ void NotebookMgr::removeNotebook(ID p_id)
try { try {
nbToRemove->remove(); nbToRemove->remove();
} catch (Exception &p_e) { } 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(), nbToRemove->getRootFolderPath(),
p_e.what()); p_e.what());
throw; throw;

View File

@ -812,7 +812,7 @@ bool ViewWindow::save(bool p_force)
MessageBoxHelper::notify(MessageBoxHelper::Warning, MessageBoxHelper::notify(MessageBoxHelper::Warning,
tr("Failed to save note (%1).").arg(m_buffer->getName()), 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("Please check the file (%1) and try it again.").arg(m_buffer->getPath()),
"", tr("Maybe the file is occupied by another service temporarily."),
this); this);
return false; return false;
} }