Skip to content

Commit

Permalink
Show more informative error message when VFS hydration fails. Display…
Browse files Browse the repository at this point in the history
… a popup and put an error into activity list. More detailed logs.

Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Oct 16, 2023
1 parent 4ca69f6 commit 2237cac
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/common/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ public slots:
void beginHydrating();
/// Emitted when the hydration ends
void doneHydrating();
// Emitted when hydration fails
void failureHydrating(int errorCode, int statusCode, const QString &errorString);

protected:
/** Setup the plugin for the folder.
Expand Down
22 changes: 22 additions & 0 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ void Folder::startVfs()

connect(_vfs.data(), &Vfs::beginHydrating, this, &Folder::slotHydrationStarts);
connect(_vfs.data(), &Vfs::doneHydrating, this, &Folder::slotHydrationDone);
connect(_vfs.data(), &Vfs::failureHydrating, this, &Folder::slotHydrationFailed);

connect(&_engine->syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
_vfs.data(), &Vfs::fileStatusChanged);
Expand Down Expand Up @@ -1510,6 +1511,27 @@ void Folder::slotHydrationDone()
emit syncStateChange();
}

void Folder::slotHydrationFailed(int errorCode, int statusCode, const QString &errorString)
{
_syncResult.setStatus(SyncResult::Error);
const auto errorMessage = tr("Virtual file download failed with code %1, status %2 and error message %3")
.arg(errorCode)
.arg(statusCode)
.arg(errorString);
const auto errorCategory = statusCode != 200 && statusCode != 204 ? ErrorCategory::NetworkError : ErrorCategory::GenericError;
slotSyncError(errorMessage, errorCategory);

const auto errorMessageBox = new QMessageBox;
errorMessageBox->setAttribute(Qt::WA_DeleteOnClose);
errorMessageBox->setText(tr("Virtual file download failed"));
errorMessageBox->setInformativeText(errorMessage);
errorMessageBox->setIcon(QMessageBox::Critical);
errorMessageBox->addButton(QMessageBox::StandardButton::Ok);
errorMessageBox->show();
errorMessageBox->activateWindow();
errorMessageBox->raise();
}

void Folder::slotCapabilitiesChanged()
{
if (_accountState->account()->capabilities().filesLockAvailable()) {
Expand Down
3 changes: 3 additions & 0 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ private slots:
/** Unblocks normal sync operation */
void slotHydrationDone();

/* Hydration failed, perform required steps to notify user */
void slotHydrationFailed(int errorCode, int statusCode, const QString &errorString);

void slotCapabilitiesChanged();

private:
Expand Down
26 changes: 23 additions & 3 deletions src/libsync/vfs/cfapi/hydrationjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ OCC::HydrationJob::Status OCC::HydrationJob::status() const
return _status;
}

int OCC::HydrationJob::errorCode() const
{
return _errorCode;
}

int OCC::HydrationJob::statusCode() const
{
return _statusCode;
}

QString OCC::HydrationJob::errorString() const
{
return _errorString;
}

void OCC::HydrationJob::start()
{
Q_ASSERT(_account);
Expand Down Expand Up @@ -334,16 +349,21 @@ void OCC::HydrationJob::finalize(OCC::VfsCfApi *vfs)

void OCC::HydrationJob::onGetFinished()
{
qCInfo(lcHydration) << "GETFileJob finished" << _requestId << _folderPath << _job->reply()->error();
_errorCode = _job->reply()->error();
_statusCode = _job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
_errorString = _job->reply()->errorString();

const auto isGetJobResultError = _job->reply()->error();
qCInfo(lcHydration) << "GETFileJob finished" << _requestId << _folderPath << _errorCode << _statusCode << _errorString;
// GETFileJob deletes itself after this signal was handled
_job = nullptr;
if (_isCancelled) {
_errorCode = 0;
_statusCode = 0;
_errorString.clear();
return;
}

if (isGetJobResultError) {
if (_errorCode) {
emitFinished(Error);
return;
}
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/vfs/cfapi/hydrationjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class HydrationJob : public QObject

Status status() const;

[[nodiscard]] int errorCode() const;
[[nodiscard]] int statusCode() const;
[[nodiscard]] QString errorString() const;

void start();
void cancel();
void finalize(OCC::VfsCfApi *vfs);
Expand Down Expand Up @@ -114,6 +118,9 @@ public slots:
QLocalSocket *_signalSocket = nullptr;
GETFileJob *_job = nullptr;
Status _status = Success;
int _errorCode = 0;
int _statusCode = 0;
QString _errorString;
};

} // namespace OCC
3 changes: 3 additions & 0 deletions src/libsync/vfs/cfapi/vfs_cfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ void VfsCfApi::onHydrationJobFinished(HydrationJob *job)
Q_ASSERT(d->hydrationJobs.contains(job));
qCInfo(lcCfApi) << "Hydration job finished" << job->requestId() << job->folderPath() << job->status();
emit hydrationRequestFinished(job->requestId());
if (!job->errorString().isEmpty()) {
emit failureHydrating(job->errorCode(), job->statusCode(), job->errorString());
}
}

int VfsCfApi::finalizeHydrationJob(const QString &requestId)
Expand Down

0 comments on commit 2237cac

Please sign in to comment.