QmlJS: Improve import error messages.

Change-Id: Ief305b787fbc4577acfdec41083bc72e178db46d
Reviewed-on: http://codereview.qt-project.org/4537
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Christian Kamm
2011-09-09 13:56:41 +02:00
parent 16b4a6fe73
commit 43a6a6d58c
2 changed files with 33 additions and 18 deletions

View File

@@ -357,7 +357,12 @@ Import Link::importNonFile(Document::Ptr doc, const ImportInfo &importInfo)
if (!importFound && importInfo.ast()) { if (!importFound && importInfo.ast()) {
error(doc, locationFromRange(importInfo.ast()->firstSourceLocation(), error(doc, locationFromRange(importInfo.ast()->firstSourceLocation(),
importInfo.ast()->lastSourceLocation()), importInfo.ast()->lastSourceLocation()),
tr("package not found")); tr("QML module not found\n\n"
"Import paths:\n"
"%1\n\n"
"For qmake projects, use the QML_IMPORT_PATH variable to add import paths.\n"
"For qmlproject projects, use the importPaths property to add import paths.").arg(
d->importPaths.join(QLatin1String("\n"))));
} }
return import; return import;
@@ -403,7 +408,7 @@ bool Link::importLibrary(Document::Ptr doc,
} }
if (errorLoc.isValid()) { if (errorLoc.isValid()) {
warning(doc, errorLoc, warning(doc, errorLoc,
tr("Library contains C++ plugins, type dump is in progress.")); tr("QML module contains C++ plugins, currently reading type information..."));
} }
} else if (libraryInfo.pluginTypeInfoStatus() == LibraryInfo::DumpError } else if (libraryInfo.pluginTypeInfoStatus() == LibraryInfo::DumpError
|| libraryInfo.pluginTypeInfoStatus() == LibraryInfo::TypeInfoFileError) { || libraryInfo.pluginTypeInfoStatus() == LibraryInfo::TypeInfoFileError) {

View File

@@ -220,23 +220,31 @@ void PluginDumper::dumpAllPlugins()
} }
} }
static QString qmldumpErrorMessage(const QString &libraryPath, const QString &error) static QString qmldumpErrorPreamble()
{ {
return PluginDumper::tr("Type dump of QML plugin in %1 failed.\nErrors:\n%2\n"). return PluginDumper::tr("QML module does not contain information about components contained in plugins.\n"
arg(libraryPath, error); "See \"Using QML Modules with Plugins\" in the documentation.") + QLatin1String("\n\n");
} }
static QString qmldumpFailedMessage(const QString &error) static QString qmldumpErrorMessage(const QString &libraryPath, const QString &error)
{
return qmldumpErrorPreamble() +
PluginDumper::tr("Automatic type dump of QML module in %1 failed.\nErrors:\n%2\n").
arg(libraryPath, error);
}
static QString qmldumpFailedMessage(const QString &libraryPath, const QString &error)
{ {
QString firstLines = QString firstLines =
QStringList(error.split(QLatin1Char('\n')).mid(0, 10)).join(QLatin1String("\n")); QStringList(error.split(QLatin1Char('\n')).mid(0, 10)).join(QLatin1String("\n"));
return PluginDumper::tr("Type dump of C++ plugin failed.\n" return qmldumpErrorPreamble() +
"First 10 lines or errors:\n" PluginDumper::tr("Automatic type dump of QML module in %1 failed.\n"
"\n" "First 10 lines or errors:\n"
"%1" "\n"
"\n" "%2"
"Check 'General Messages' output pane for details." "\n"
).arg(firstLines); "Check 'General Messages' output pane for details."
).arg(libraryPath, firstLines);
} }
static void printParseWarnings(const QString &libraryPath, const QString &warning) static void printParseWarnings(const QString &libraryPath, const QString &warning)
@@ -279,7 +287,7 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
Core::MessageManager *messageManager = Core::MessageManager::instance(); Core::MessageManager *messageManager = Core::MessageManager::instance();
const QString errorMessages = process->readAllStandardError(); const QString errorMessages = process->readAllStandardError();
messageManager->printToOutputPane(qmldumpErrorMessage(libraryPath, errorMessages)); messageManager->printToOutputPane(qmldumpErrorMessage(libraryPath, errorMessages));
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(errorMessages)); libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(libraryPath, errorMessages));
} }
const QByteArray output = process->readAllStandardOutput(); const QByteArray output = process->readAllStandardOutput();
@@ -288,7 +296,8 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(output, &error, &warning); QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(output, &error, &warning);
if (exitCode == 0) { if (exitCode == 0) {
if (!error.isEmpty()) { if (!error.isEmpty()) {
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, tr("Type dump of C++ plugin failed. Parse error:\n'%1'").arg(error)); libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError,
qmldumpErrorMessage(libraryPath, error));
} else { } else {
libraryInfo.setMetaObjects(objectsList); libraryInfo.setMetaObjects(objectsList);
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpDone); libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpDone);
@@ -319,7 +328,7 @@ void PluginDumper::qmlPluginTypeDumpError(QProcess::ProcessError)
if (!libraryPath.isEmpty()) { if (!libraryPath.isEmpty()) {
const Snapshot snapshot = m_modelManager->snapshot(); const Snapshot snapshot = m_modelManager->snapshot();
LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath); LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath);
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(errorMessages)); libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(libraryPath, errorMessages));
m_modelManager->updateLibraryInfo(libraryPath, libraryInfo); m_modelManager->updateLibraryInfo(libraryPath, libraryInfo);
} }
} }
@@ -398,8 +407,9 @@ void PluginDumper::dump(const Plugin &plugin)
return; return;
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError,
tr("Could not locate the helper application for dumping type information from C++ plugins.\n" qmldumpErrorMessage(plugin.qmldirPath,
"Please build the debugging helpers on the Qt version options page.")); tr("Could not locate the helper application for dumping type information from C++ plugins.\n"
"Please build the qmldump applcation on the Qt version options page.")));
m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo); m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo);
return; return;
} }