forked from quickshell/quickshell
		
	core: improve log format for QML errors and warnings
This commit is contained in:
		
							parent
							
								
									4472b27039
								
							
						
					
					
						commit
						ec433d1a70
					
				
					 3 changed files with 44 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -8,11 +8,13 @@
 | 
			
		|||
#include <qfileinfo.h>
 | 
			
		||||
#include <qfilesystemwatcher.h>
 | 
			
		||||
#include <qhash.h>
 | 
			
		||||
#include <qlist.h>
 | 
			
		||||
#include <qlogging.h>
 | 
			
		||||
#include <qloggingcategory.h>
 | 
			
		||||
#include <qobject.h>
 | 
			
		||||
#include <qqmlcontext.h>
 | 
			
		||||
#include <qqmlengine.h>
 | 
			
		||||
#include <qqmlerror.h>
 | 
			
		||||
#include <qqmlincubator.h>
 | 
			
		||||
#include <qtmetamacros.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +26,10 @@
 | 
			
		|||
#include "reload.hpp"
 | 
			
		||||
#include "scan.hpp"
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
Q_LOGGING_CATEGORY(logScene, "scene");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static QHash<const QQmlEngine*, EngineGeneration*> g_generations; // NOLINT
 | 
			
		||||
 | 
			
		||||
EngineGeneration::EngineGeneration(const QDir& rootPath, QmlScanner scanner)
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +40,9 @@ EngineGeneration::EngineGeneration(const QDir& rootPath, QmlScanner scanner)
 | 
			
		|||
    , engine(new QQmlEngine()) {
 | 
			
		||||
	g_generations.insert(this->engine, this);
 | 
			
		||||
 | 
			
		||||
	this->engine->setOutputWarningsToStandardError(false);
 | 
			
		||||
	QObject::connect(this->engine, &QQmlEngine::warnings, this, &EngineGeneration::onEngineWarnings);
 | 
			
		||||
 | 
			
		||||
	this->engine->addUrlInterceptor(&this->urlInterceptor);
 | 
			
		||||
	this->engine->setNetworkAccessManagerFactory(&this->interceptNetFactory);
 | 
			
		||||
	this->engine->setIncubationController(&this->delayedIncubationController);
 | 
			
		||||
| 
						 | 
				
			
			@ -312,6 +321,22 @@ void EngineGeneration::incubationControllerDestroyed() {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::onEngineWarnings(const QList<QQmlError>& warnings) const {
 | 
			
		||||
	for (const auto& error: warnings) {
 | 
			
		||||
		auto rel = "**/" % this->rootPath.relativeFilePath(error.url().path());
 | 
			
		||||
 | 
			
		||||
		QString objectName;
 | 
			
		||||
		auto desc = error.description();
 | 
			
		||||
		if (auto i = desc.indexOf(": "); i != -1) {
 | 
			
		||||
			objectName = desc.first(i);
 | 
			
		||||
			desc = desc.sliced(i + 2);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		qCWarning(logScene).noquote().nospace() << objectName << " at " << rel << '[' << error.line()
 | 
			
		||||
		                                        << ':' << error.column() << "]: " << desc;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EngineGeneration::registerExtension(const void* key, EngineGenerationExt* extension) {
 | 
			
		||||
	if (this->extensions.contains(key)) {
 | 
			
		||||
		delete this->extensions.value(key);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,8 +4,10 @@
 | 
			
		|||
#include <qdir.h>
 | 
			
		||||
#include <qfilesystemwatcher.h>
 | 
			
		||||
#include <qhash.h>
 | 
			
		||||
#include <qlist.h>
 | 
			
		||||
#include <qobject.h>
 | 
			
		||||
#include <qqmlengine.h>
 | 
			
		||||
#include <qqmlerror.h>
 | 
			
		||||
#include <qqmlincubator.h>
 | 
			
		||||
#include <qtclasshelpermacros.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -82,6 +84,7 @@ private slots:
 | 
			
		|||
	void onFileChanged(const QString& name);
 | 
			
		||||
	void onDirectoryChanged();
 | 
			
		||||
	void incubationControllerDestroyed();
 | 
			
		||||
	void onEngineWarnings(const QList<QQmlError>& warnings) const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void postReload();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,6 @@
 | 
			
		|||
#include "../window/floatingwindow.hpp"
 | 
			
		||||
#include "generation.hpp"
 | 
			
		||||
#include "instanceinfo.hpp"
 | 
			
		||||
#include "logging.hpp"
 | 
			
		||||
#include "qmlglobal.hpp"
 | 
			
		||||
#include "scan.hpp"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +31,6 @@ RootWrapper::RootWrapper(QString rootPath, QString shellId)
 | 
			
		|||
	this->reloadGraph(true);
 | 
			
		||||
 | 
			
		||||
	if (this->generation == nullptr) {
 | 
			
		||||
		qCritical() << "could not create scene graph, exiting";
 | 
			
		||||
		exit(-1); // NOLINT
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +52,7 @@ void RootWrapper::reloadGraph(bool hard) {
 | 
			
		|||
 | 
			
		||||
	// todo: move into EngineGeneration
 | 
			
		||||
	if (this->generation != nullptr) {
 | 
			
		||||
		qInfo() << "Reloading configuration...";
 | 
			
		||||
		QuickshellSettings::reset();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,9 +64,17 @@ void RootWrapper::reloadGraph(bool hard) {
 | 
			
		|||
	auto component = QQmlComponent(generation->engine, url);
 | 
			
		||||
 | 
			
		||||
	if (!component.isReady()) {
 | 
			
		||||
		qCritical() << "Failed to load configuration:";
 | 
			
		||||
		auto error = component.errorString().trimmed();
 | 
			
		||||
		qCCritical(logBare).noquote() << error;
 | 
			
		||||
		qCritical() << "Failed to load configuration";
 | 
			
		||||
		QString errorString = "Failed to load configuration";
 | 
			
		||||
 | 
			
		||||
		auto errors = component.errors();
 | 
			
		||||
		for (auto& error: errors) {
 | 
			
		||||
			auto rel = "**/" % rootPath.relativeFilePath(error.url().path());
 | 
			
		||||
			auto msg = "  caused by " % rel % '[' % QString::number(error.line()) % ':'
 | 
			
		||||
			         % QString::number(error.column()) % "]: " % error.description();
 | 
			
		||||
			errorString += '\n' % msg;
 | 
			
		||||
			qCritical().noquote() << msg;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		auto newFiles = generation->scanner.scannedFiles;
 | 
			
		||||
		generation->destroy();
 | 
			
		||||
| 
						 | 
				
			
			@ -80,15 +87,16 @@ void RootWrapper::reloadGraph(bool hard) {
 | 
			
		|||
			auto showPopup = true;
 | 
			
		||||
			if (this->generation->qsgInstance != nullptr) {
 | 
			
		||||
				this->generation->qsgInstance->clearReloadPopupInhibit();
 | 
			
		||||
				emit this->generation->qsgInstance->reloadFailed(error);
 | 
			
		||||
				emit this->generation->qsgInstance->reloadFailed(errorString);
 | 
			
		||||
				showPopup = !this->generation->qsgInstance->isReloadPopupInhibited();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (showPopup) qs::ui::ReloadPopup::spawnPopup(InstanceInfo::CURRENT.instanceId, true, error);
 | 
			
		||||
			if (showPopup)
 | 
			
		||||
				qs::ui::ReloadPopup::spawnPopup(InstanceInfo::CURRENT.instanceId, true, errorString);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (this->generation != nullptr && this->generation->qsgInstance != nullptr) {
 | 
			
		||||
			emit this->generation->qsgInstance->reloadFailed(error);
 | 
			
		||||
			emit this->generation->qsgInstance->reloadFailed(errorString);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue