[PATCH 3/4] Get more descriptive error messages when uploading to divelogs.de

Thiago Macieira thiago at macieira.org
Mon Dec 16 09:06:53 UTC 2013


Signed-off-by: Thiago Macieira <thiago at macieira.org>
---
 qt-ui/subsurfacewebservices.cpp | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 775c7b1..f9b6647 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -102,7 +102,7 @@ QString DivelogsDeWebServices::prepare_dives_for_divelogs(const bool selected, Q
 {
 	static const char errPrefix[] = "divelog.de-upload:";
 	if (!amount_selected) {
-		qDebug() << errPrefix << "no dives selected";
+		*errorMsg = tr("no dives were selected");
 		return QString();
 	}
 
@@ -125,10 +125,14 @@ QString DivelogsDeWebServices::prepare_dives_for_divelogs(const bool selected, Q
 
 	/* generate a random filename and create/open that file with zip_open */
 	QString tempfile = QDir::tempPath() + "/import-" + QString::number(qrand() % 99999999) + ".dld";
-	zip = zip_open(QFile::encodeName(tempfile), ZIP_CREATE, NULL);
 
+	int error_code;
+	zip = zip_open(QFile::encodeName(tempfile), ZIP_CREATE, &error_code);
 	if (!zip) {
-		qDebug() << errPrefix << "cannot open file as zip";
+		char buffer[1024];
+		zip_error_to_str(buffer, sizeof buffer, error_code, errno);
+		*errorMsg = tr("failed to create zip file for upload: %1")
+			    .arg(QString::fromLocal8Bit(buffer));
 		return QString();
 	}
 
@@ -141,7 +145,7 @@ QString DivelogsDeWebServices::prepare_dives_for_divelogs(const bool selected, Q
 			continue;
 		f = tmpfile();
 		if (!f) {
-			qDebug() << errPrefix << "cannot create temp file";
+			*errorMsg = tr("cannot create temporary file: %1").arg(qt_error_string());
 			goto error_close_zip;
 		}
 		save_dive(f, dive);
@@ -150,7 +154,7 @@ QString DivelogsDeWebServices::prepare_dives_for_divelogs(const bool selected, Q
 		rewind(f);
 		membuf = (char *)malloc(streamsize + 1);
 		if (!membuf || !fread(membuf, streamsize, 1, f)) {
-			qDebug() << errPrefix << "memory error";
+			*errorMsg = tr("internal error: %1").arg(qt_error_string());
 			fclose(f);
 			free((void *)membuf);
 			goto error_close_zip;
@@ -164,7 +168,8 @@ QString DivelogsDeWebServices::prepare_dives_for_divelogs(const bool selected, Q
 		 */
 		xmlDoc *doc = xmlReadMemory(membuf, streamsize, "divelog", NULL, 0);
 		if (!doc) {
-			qDebug() << errPrefix << "xml error";
+			qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
+			*errorMsg = tr("internal error");
 			free((void *)membuf);
 			goto error_close_zip;
 		}
@@ -551,8 +556,8 @@ void DivelogsDeWebServices::downloadDives()
 
 void DivelogsDeWebServices::prepareDivesForUpload()
 {
-	QString errorText(tr("Cannot create DLD file"));
-	QString filename = prepare_dives_for_divelogs(true);
+	QString errorText;
+	QString filename = prepare_dives_for_divelogs(true, &errorText);
 	if (!filename.isEmpty()) {
 		QFile f(filename);
 		if (f.open(QIODevice::ReadOnly)) {
@@ -561,10 +566,8 @@ void DivelogsDeWebServices::prepareDivesForUpload()
 			f.remove();
 			return;
 		}
-		mainWindow()->showError(errorText.append(": ").append(filename));
-		return;
 	}
-	mainWindow()->showError(errorText.append("!"));
+	mainWindow()->showError(errorText);
 }
 
 void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
-- 
1.7.11.7



More information about the subsurface mailing list