1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Improved error reporting

This commit is contained in:
Martin Tůma 2022-07-08 02:08:21 +02:00
parent efd496d38c
commit 8b4daa43e3
3 changed files with 20 additions and 14 deletions

View File

@ -121,6 +121,13 @@ Data::Data(const QString &fileName, bool tryUnknown)
file.reset();
++it;
}
qWarning("%s:", qPrintable(fileName));
for (it = _parsers.find(suffix); it != _parsers.end()
&& it.key() == suffix; it++)
qWarning(" %s: line %d: %s", qPrintable(it.key()),
it.value()->errorLine(), qPrintable(it.value()->errorString()));
} else if (tryUnknown) {
for (it = _parsers.begin(); it != _parsers.end(); it++) {
if (it.value()->parse(&file, trackData, routeData, _polygons,
@ -132,9 +139,9 @@ Data::Data(const QString &fileName, bool tryUnknown)
file.reset();
}
qWarning("Error loading data file: %s:", qPrintable(fileName));
qWarning("%s:", qPrintable(fileName));
for (it = _parsers.begin(); it != _parsers.end(); it++)
qWarning("%s: line %d: %s", qPrintable(it.key()),
qWarning(" %s: line %d: %s", qPrintable(it.key()),
it.value()->errorLine(), qPrintable(it.value()->errorString()));
_errorLine = 0;

View File

@ -62,36 +62,35 @@ Map *MapList::loadFile(const QString &path, const Projection &proj, bool *isDir)
QFileInfo fi(path);
QString suffix(fi.suffix().toLower());
Map *map = 0;
QStringList errors;
if ((it = _parsers.find(suffix)) != _parsers.end()) {
while (it != _parsers.end() && it.key() == suffix) {
delete map;
map = it.value()(path, proj, isDir);
if (map->isValid())
break;
return map;
else
errors.append(it.key() + ": " + map->errorString());
++it;
}
} else {
QStringList errors;
} else {
for (it = _parsers.begin(); it != _parsers.end(); it++) {
map = it.value()(path, proj, isDir);
if (map->isValid())
break;
return map;
else {
errors.append(it.key() + ": " + map->errorString());
delete map;
map = 0;
}
}
}
if (!map) {
qWarning("Error loading map file: %s:", qPrintable(path));
qWarning("%s:", qPrintable(path));
for (int i = 0; i < errors.size(); i++)
qWarning("%s", qPrintable(errors.at(i)));
}
}
qWarning(" %s", qPrintable(errors.at(i)));
return map ? map : new InvalidMap(path, "Unknown file format");
}

View File

@ -16,7 +16,7 @@ WLDFile::WLDFile(const QString &fileName)
QByteArray line(file.readLine(128).trimmed());
val[i] = line.toDouble(&ok);
if (!ok) {
_errorString = line + ": invalid parameter";
_errorString = QString("Parse error on line %1").arg(i+1);
return;
}
}