Long Running Put: Better error reporting

This commit is contained in:
Olivier Goffart 2014-07-29 15:51:22 +02:00
parent 7480d34742
commit 550d6d66d1
7 changed files with 34 additions and 18 deletions

View file

@ -462,12 +462,14 @@ void CleanupPollsJob::slotPollFinished()
{ {
PollJob *job = qobject_cast<PollJob *>(sender()); PollJob *job = qobject_cast<PollJob *>(sender());
Q_ASSERT(job); Q_ASSERT(job);
if (!job->_error.isEmpty()) { if (job->_item._status == SyncFileItem::FatalError) {
qDebug() << "There was an error with file " << job->_item._file << job->_error ; emit aborted(job->_item._errorString);
return;
} else if (job->_item._status != SyncFileItem::Success) {
qDebug() << "There was an error with file " << job->_item._file << job->_item._errorString;
} else { } else {
_journal->setFileRecord(SyncJournalFileRecord(job->_item, _localPath + job->_item._file)); _journal->setFileRecord(SyncJournalFileRecord(job->_item, _localPath + job->_item._file));
} }
// Continue with the next entry, or finish // Continue with the next entry, or finish
start(); start();
} }

View file

@ -271,6 +271,7 @@ public:
void start(); void start();
signals: signals:
void finished(); void finished();
void aborted(const QString &error);
private slots: private slots:
void slotPollFinished(); void slotPollFinished();
}; };

View file

@ -96,28 +96,34 @@ bool PollJob::finished()
{ {
QNetworkReply::NetworkError err = reply()->error(); QNetworkReply::NetworkError err = reply()->error();
if (err != QNetworkReply::NoError) { if (err != QNetworkReply::NoError) {
_item._httpErrorCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
_item._status = classifyError(err, _item._httpErrorCode);
_item._errorString = reply()->errorString();
if (_item._status == SyncFileItem::FatalError || int(_item._httpErrorCode / 100) == 4) {
emit finishedSignal();
return true;
}
start();
return false; return false;
} }
bool ok = false; bool ok = false;
QVariantMap status = QtJson::parse(QString::fromUtf8(reply()->readAll()), ok).toMap(); QVariantMap status = QtJson::parse(QString::fromUtf8(reply()->readAll()), ok).toMap();
if (!ok || status.isEmpty()) { if (!ok || status.isEmpty()) {
qDebug() << "Invalid json reply from the poll URL"; _item._errorString = tr("Invalid json reply from the poll URL");
_item._status = SyncFileItem::NormalError;
emit finishedSignal(); emit finishedSignal();
// FIXME: retry?
return true; return true;
} }
// the following code only happens after all chunks were uploaded. if (status["unfinished"].isValid()) {
// the file id should only be empty for new files up- or downloaded start();
QByteArray fid = status["fileid"].toByteArray(); return false;
if( !fid.isEmpty() ) {
if( !_item._fileId.isEmpty() && _item._fileId != fid ) {
qDebug() << "WARN: File ID changed!" << _item._fileId << fid;
}
_item._fileId = fid;
} }
_item._errorString = status["error"].toString();
_item._status = _item._errorString.isEmpty() ? SyncFileItem::NormalError : SyncFileItem::Success;
_item._fileId = status["fileid"].toByteArray();
_item._etag = status["etag"].toByteArray(); _item._etag = status["etag"].toByteArray();
_item._responseTimeStamp = responseTimestamp(); _item._responseTimeStamp = responseTimestamp();
@ -462,8 +468,8 @@ void PropagateUploadFileQNAM::slotPollFinished()
PollJob *job = qobject_cast<PollJob *>(sender()); PollJob *job = qobject_cast<PollJob *>(sender());
Q_ASSERT(job); Q_ASSERT(job);
if (!job->_error.isEmpty()) { if (job->_item._status != SyncFileItem::Success) {
done(SyncFileItem::NormalError, job->_error); done(job->_item._status, job->_item._errorString);
return; return;
} }

View file

@ -86,9 +86,8 @@ class PollJob : public AbstractNetworkJob {
QString _localPath; QString _localPath;
public: public:
SyncFileItem _item; SyncFileItem _item;
const QString _error;
// Takes ownership of the device // Takes ownership of the device
explicit PollJob(Account* account, const QString &path, SyncFileItem item, explicit PollJob(Account* account, const QString &path, const SyncFileItem &item,
SyncJournalDb *journal, const QString &localPath, QObject *parent) SyncJournalDb *journal, const QString &localPath, QObject *parent)
: AbstractNetworkJob(account, path, parent), _journal(journal), _localPath(localPath), _item(item) {} : AbstractNetworkJob(account, path, parent), _journal(journal), _localPath(localPath), _item(item) {}

View file

@ -445,6 +445,7 @@ void SyncEngine::startSync()
CleanupPollsJob *job = new CleanupPollsJob(pollInfos, AccountManager::instance()->account(), CleanupPollsJob *job = new CleanupPollsJob(pollInfos, AccountManager::instance()->account(),
_journal, _localPath, this); _journal, _localPath, this);
connect(job, SIGNAL(finished()), this, SLOT(startSync())); connect(job, SIGNAL(finished()), this, SLOT(startSync()));
connect(job, SIGNAL(aborted(QString)), this, SLOT(slotCleanPollsJobAborted(QString)));
job->start(); job->start();
return; return;
} }
@ -623,6 +624,12 @@ void SyncEngine::slotUpdateFinished(int updateResult)
_propagator->start(_syncedItems); _propagator->start(_syncedItems);
} }
void SyncEngine::slotCleanPollsJobAborted(const QString &error)
{
csyncError(error);
finalize();
}
void SyncEngine::setNetworkLimits(int upload, int download) void SyncEngine::setNetworkLimits(int upload, int download)
{ {
_uploadLimit = upload; _uploadLimit = upload;

View file

@ -93,6 +93,7 @@ private slots:
void slotProgress(const SyncFileItem& item, quint64 curent); void slotProgress(const SyncFileItem& item, quint64 curent);
void slotAdjustTotalTransmissionSize(qint64 change); void slotAdjustTotalTransmissionSize(qint64 change);
void slotUpdateFinished(int updateResult); void slotUpdateFinished(int updateResult);
void slotCleanPollsJobAborted(const QString &error);
private: private:
void handleSyncError(CSYNC *ctx, const char *state); void handleSyncError(CSYNC *ctx, const char *state);

View file

@ -204,7 +204,7 @@ bool SyncJournalDb::checkConnect()
} }
createQuery.prepare("CREATE TABLE IF NOT EXISTS version(" createQuery.prepare("CREATE TABLE IF NOT EXISTS version("
"major VARCHAR(4096)," "major INTEGER(8),"
"minor INTEGER(8)," "minor INTEGER(8),"
"patch INTEGER(8)," "patch INTEGER(8),"
"custom VARCHAR(256)" "custom VARCHAR(256)"