Polish error messages for import failures

If you have a loop in your qmldir imports, you get an abhorrent amount
of spam terminating with a misformatted message. Let's limit the total
length of the message and fix the formatting.

Amends commit c7c4c8f088.
Amends commit a0290dcc53.

Pick-to: 6.5
Fixes: QTBUG-110808
Change-Id: I46fa944eacbca456964d1a98fe029f6d550c0a8c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2023-02-03 11:03:17 +01:00
parent 8f60ffc42b
commit 7e51a3fd91
1 changed files with 8 additions and 5 deletions

View File

@ -631,17 +631,20 @@ bool QQmlTypeLoader::Blob::addLibraryImport(const QQmlTypeLoader::Blob::PendingI
if (!loadImportDependencies(import, qmldirFilePath, import->flags, errors)) {
QQmlError error;
QString reason = errors->front().description();
if (reason.size() > 512)
reason = reason.first(252) + QLatin1String("... ...") + reason.last(252);
if (import->version.hasMajorVersion()) {
error.setDescription(QQmlImportDatabase::tr(
"module \"%1\" version %2.%3 cannot be imported because\n%4")
"module \"%1\" version %2.%3 cannot be imported because:\n%4")
.arg(import->uri).arg(import->version.majorVersion())
.arg(import->version.hasMinorVersion()
? QString::number(import->version.minorVersion())
: QLatin1String("x"))
.arg(errors->front().description()));
.arg(reason));
} else {
error.setDescription(QQmlImportDatabase::tr("module \"%1\" cannot be imported because\n%2")
.arg(import->uri, errors->front().description()));
error.setDescription(QQmlImportDatabase::tr("module \"%1\" cannot be imported because:\n%2")
.arg(import->uri, reason));
}
errors->prepend(error);
return false;
@ -826,7 +829,7 @@ bool QQmlTypeLoader::Blob::loadImportDependencies(
case QQmlImportInstance::Lowest: {
QQmlError error;
error.setDescription(
QString::fromLatin1("Too many dependent imports")
QString::fromLatin1("Too many dependent imports for %1 %2.%3")
.arg(currentImport->uri)
.arg(currentImport->version.majorVersion())
.arg(currentImport->version.minorVersion()));