QmlDesigner: Cleanup exceptions

Remoing unused exceptions and using source_location to simplify the
code. QmlDesigner::Exception is now derived from Sqlite::Exception.

Task-number: QDS-14575
Change-Id: I36325e6113313ae1e6c0b0fdc183be86f920db94
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-01-22 16:18:41 +01:00
parent a3d86d5b8e
commit 2c0f17d0e1
51 changed files with 144 additions and 952 deletions

View File

@@ -10,8 +10,6 @@
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <invalidqmlsourceexception.h>
#include <coreplugin/messagebox.h>
#include <coreplugin/icore.h>

View File

@@ -116,12 +116,12 @@ T jsonSafeValue(const QJsonObject &jsonObject, const QString &symbolName,
std::function<bool (const T&)> validityCheck = [](const T&) -> bool {return true;})
{
if (!jsonObject.contains(symbolName))
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, symbolName.toLatin1());
throw InvalidArgumentException(symbolName);
QVariant symbolVar = jsonObject.value(symbolName);
T extractedVal = symbolVar.value<T>();
if (!validityCheck(extractedVal))
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, symbolName.toLatin1());
throw InvalidArgumentException(symbolName);
return extractedVal;
}
@@ -138,7 +138,7 @@ QSize jsonSafeSize(const QJsonObject &jsonObject, const QString &symbolName)
if (wOk && hOk)
return {cWidth, cHeight};
}
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, symbolName.toLatin1());
throw InvalidArgumentException(symbolName);
return {};
}
@@ -151,7 +151,7 @@ T jsonSafeMetaEnum(const QJsonObject &jsonObject, const QString &symbolName = De
if (ok)
return enumIndex;
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, symbolName.toLatin1());
throw InvalidArgumentException(symbolName);
return {};
}

View File

@@ -10,8 +10,6 @@
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <invalidqmlsourceexception.h>
#include <coreplugin/messagebox.h>
#include <coreplugin/icore.h>

View File

@@ -9,8 +9,6 @@
#include <qrcodegen/src/qrcodeimageprovider.h>
#include <theme.h>
#include <invalidqmlsourceexception.h>
#include <coreplugin/messagebox.h>
#include <coreplugin/icore.h>

View File

@@ -19,7 +19,6 @@
#include <designersettings.h>
#include <designmodewidget.h>
#include <import.h>
#include <invalididexception.h>
#include <itemlibraryentry.h>
#include <materialutils.h>
#include <modelutils.h>

View File

@@ -14,7 +14,6 @@
#include <qmldesignerconstants.h>
#include <qmltimeline.h>
#include <invalididexception.h>
#include <rewritingexception.h>
#include <variantproperty.h>

View File

@@ -11,8 +11,6 @@
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <invalidqmlsourceexception.h>
#include <coreplugin/messagebox.h>
#include <coreplugin/icore.h>

View File

@@ -80,19 +80,17 @@ extend_qtc_library(QmlDesignerCore
SOURCES
exception.cpp
invalidargumentexception.cpp
invalididexception.cpp
invalidmetainfoexception.cpp
invalidmodelnodeexception.cpp
invalidmodelstateexception.cpp
invalidpropertyexception.cpp
invalidqmlsourceexception.cpp
invalidreparentingexception.cpp
invalidslideindexexception.cpp
notimplementedexception.cpp
removebasestateexception.cpp
rewritingexception.cpp
)
extend_qtc_library(QmlDesignerCore
CONDITION NOT USE_PROJECTSTORAGE
INCLUDES exceptions
SOURCES_PREFIX exceptions
SOURCES
invalidmetainfoexception.cpp
)
extend_qtc_library(QmlDesignerCore
INCLUDES filemanager
SOURCES_PREFIX filemanager
@@ -186,6 +184,7 @@ extend_qtc_library(QmlDesignerCore
CONDITION NOT USE_PROJECTSTORAGE
SOURCES_PREFIX include
SOURCES
invalidmetainfoexception.h
itemlibraryinfo.h
metainforeader.h
subcomponentmanager.h
@@ -214,14 +213,6 @@ extend_qtc_library(QmlDesignerCore
imagecacheauxiliarydata.h
import.h
invalidargumentexception.h
invalididexception.h
invalidmetainfoexception.h
invalidmodelnodeexception.h
invalidmodelstateexception.h
invalidpropertyexception.h
invalidqmlsourceexception.h
invalidreparentingexception.h
invalidslideindexexception.h
iwidgetplugin.h
mathutils.h
modelfwd.h
@@ -233,7 +224,6 @@ extend_qtc_library(QmlDesignerCore
nodelistproperty.h
nodemetainfo.h
nodeproperty.h
notimplementedexception.h
objectpropertybinding.h
projectstorageids.h
propertybinding.h
@@ -244,7 +234,6 @@ extend_qtc_library(QmlDesignerCore
qmldesignercorelib_exports.h
qmldesignercorelib_global.h
qmldesignercoreconstants.h
removebasestateexception.h
rewritertransaction.h
rewritingexception.h
signalhandlerproperty.h

View File

@@ -4,9 +4,6 @@
#include <abstractview.h>
#include <bindingproperty.h>
#include <invalididexception.h>
#include <invalidmodelnodeexception.h>
#include <invalidreparentingexception.h>
#include <modelmerger.h>
#include <nodeabstractproperty.h>
#include <nodelistproperty.h>
@@ -250,20 +247,10 @@ void StylesheetMerger::preprocessStyleSheet()
newParentProperty.slide(styleParentIndex, templateParentIndex);
}
transaction.commit();
}catch (InvalidIdException &ide) {
qDebug().noquote() << "Invalid id exception while preprocessing the style sheet.";
ide.createWarning();
} catch (InvalidReparentingException &rpe) {
qDebug().noquote() << "Invalid reparenting exception while preprocessing the style sheet.";
rpe.createWarning();
} catch (InvalidModelNodeException &mne) {
qDebug().noquote() << "Invalid model node exception while preprocessing the style sheet.";
mne.createWarning();
} catch (Exception &e) {
} catch (Exception &exception) {
qDebug().noquote() << "Exception while preprocessing the style sheet.";
e.createWarning();
qDebug() << exception;
}
}
void StylesheetMerger::replaceNode(ModelNode &replacedNode, ModelNode &newNode)
@@ -313,18 +300,9 @@ void StylesheetMerger::replaceRootNode(ModelNode& templateRootNode)
ModelNode newRoot = m_templateView->rootModelNode();
newRoot.setIdWithoutRefactoring(rootId);
transaction.commit();
} catch (InvalidIdException &ide) {
qDebug().noquote() << "Invalid id exception while replacing root node of template.";
ide.createWarning();
} catch (InvalidReparentingException &rpe) {
qDebug().noquote() << "Invalid reparenting exception while replacing root node of template.";
rpe.createWarning();
} catch (InvalidModelNodeException &mne) {
qDebug().noquote() << "Invalid model node exception while replacing root node of template.";
mne.createWarning();
} catch (Exception &e) {
} catch (Exception &exception) {
qDebug().noquote() << "Exception while replacing root node of template.";
e.createWarning();
qDebug() << exception;
}
}
@@ -397,18 +375,9 @@ void StylesheetMerger::parseTemplateOptions()
RewriterTransaction transaction(m_templateView, "remove-options-node");
optionsNode.destroy();
transaction.commit();
} catch (InvalidIdException &ide) {
qDebug().noquote() << "Invalid id exception while removing options from template.";
ide.createWarning();
} catch (InvalidReparentingException &rpe) {
qDebug().noquote() << "Invalid reparenting exception while removing options from template.";
rpe.createWarning();
} catch (InvalidModelNodeException &mne) {
qDebug().noquote() << "Invalid model node exception while removing options from template.";
mne.createWarning();
} catch (Exception &e) {
} catch (Exception &exception) {
qDebug().noquote() << "Exception while removing options from template.";
e.createWarning();
qDebug() << exception;
}
}
@@ -483,9 +452,9 @@ void StylesheetMerger::mergeStates(ModelNode &outputNode, const ModelNode &input
ModelNode stateClone = merger.insertModel(inputStateNode);
if (stateClone.isValid())
outputNode.nodeListProperty("states").reparentHere(stateClone);
} catch (Exception &e) {
} catch (Exception &exception) {
qDebug().noquote() << "Exception while merging states.";
e.createWarning();
qDebug() << exception;
}
}
}
@@ -542,21 +511,9 @@ void StylesheetMerger::merge()
replaceNode(replacedNode, replacementNode);
transaction.commit();
} catch (InvalidIdException &ide) {
qDebug().noquote() << "Invalid id exception while replacing template node";
ide.createWarning();
continue;
} catch (InvalidReparentingException &rpe) {
qDebug().noquote() << "Invalid reparenting exception while replacing template node";
rpe.createWarning();
continue;
} catch (InvalidModelNodeException &mne) {
qDebug().noquote() << "Invalid model node exception while replacing template node";
mne.createWarning();
continue;
} catch (Exception &e) {
} catch (Exception &exception) {
qDebug().noquote() << "Exception while replacing template node.";
e.createWarning();
qDebug() << exception;
continue;
}
}
@@ -584,21 +541,9 @@ void StylesheetMerger::merge()
}
}
transaction.commit();
} catch (InvalidIdException &ide) {
qDebug().noquote() << "Invalid id exception while syncing style properties to template";
ide.createWarning();
continue;
} catch (InvalidReparentingException &rpe) {
qDebug().noquote() << "Invalid reparenting exception while syncing style properties to template";
rpe.createWarning();
continue;
} catch (InvalidModelNodeException &mne) {
qDebug().noquote() << "Invalid model node exception while syncing style properties to template";
mne.createWarning();
continue;
} catch (Exception &e) {
} catch (Exception &exception) {
qDebug().noquote() << "Exception while syncing style properties.";
e.createWarning();
qDebug() << exception;
continue;
}
}

View File

@@ -14,55 +14,9 @@
#include <functional>
/*!
\defgroup CoreExceptions
*/
/*!
\class QmlDesigner::Exception
\ingroup CoreExceptions
\brief The Exception class is the abstract base class for all exceptions.
Exceptions should be used if there is no other way to indicate that
something is going wrong. For example,
the result would be a inconsistent model or a crash.
*/
namespace QmlDesigner {
#ifdef Q_OS_LINUX
const char* demangle(const char* name)
{
char buf[1024];
size_t size = 1024;
int status;
char* res;
res = abi::__cxa_demangle(name,
buf,
&size,
&status);
return res;
}
#else
const char* demangle(const char* name)
{
return name;
}
#endif
bool Exception::s_shouldAssert = false;
void Exception::setShouldAssert(bool assert)
{
s_shouldAssert = assert;
}
bool Exception::shouldAssert()
{
return s_shouldAssert;
}
bool Exception::s_warnAboutException = true;
void Exception::setWarnAboutException(bool warn)
@@ -75,63 +29,22 @@ bool Exception::warnAboutException()
return s_warnAboutException;
}
#ifdef Q_OS_LINUX
static QString getBackTrace()
namespace {
#if defined(__cpp_lib_stacktrace) && __cpp_lib_stacktrace >= 202011L
QString getBackTrace()
{
QString backTrace;
void * array[50];
int nSize = backtrace(array, 50);
char ** symbols = backtrace_symbols(array, nSize);
for (int i = 0; i < nSize; i++)
backTrace.append(QString("%1\n").arg(QLatin1String(symbols[i])));
free(symbols);
return backTrace;
auto trace = std::stacktrace::current();
return QString::fromStdString(std::to_string(trace));
}
#endif
} // namespace
QString Exception::defaultDescription(int line, const QByteArray &function, const QByteArray &file)
QString Exception::defaultDescription(const Sqlite::source_location &sourceLocation)
{
return QString(QStringLiteral("file: %1, function: %2, line: %3"))
.arg(QString::fromUtf8(file), QString::fromUtf8(function), QString::number(line));
}
/*!
Constructs an exception. \a line uses the __LINE__ macro, \a function uses
the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
Exception::Exception(int line, const QByteArray &function, const QByteArray &file)
: Exception(line, function, file, Exception::defaultDescription(line, function, file))
{ }
Exception::Exception(int line, const QByteArray &function,
const QByteArray &file, const QString &description)
: m_line(line)
, m_function(QString::fromUtf8(function))
, m_file(QString::fromUtf8(file))
, m_description(description)
#ifdef Q_OS_LINUX
, m_backTrace(getBackTrace())
#endif
{
if (s_shouldAssert) {
qDebug() << Exception::description();
QTC_ASSERT(false, ;);
Q_ASSERT(false);
}
}
Exception::~Exception() = default;
/*!
Returns the unmangled backtrace of this exception as a string.
*/
QString Exception::backTrace() const
{
return m_backTrace;
return QStringView(u"file: %1, function: %2, line: %3")
.arg(QLatin1StringView{sourceLocation.file_name()},
QLatin1StringView{sourceLocation.function_name()},
QString::number(sourceLocation.line()));
}
void Exception::createWarning() const
@@ -140,13 +53,6 @@ void Exception::createWarning() const
qDebug() << *this;
}
/*!
Returns the optional description of this exception as a string.
*/
QString Exception::description() const
{
return m_description;
}
namespace {
std::function<void(QStringView title, QStringView description)> showExceptionCallback;
}
@@ -157,7 +63,7 @@ std::function<void(QStringView title, QStringView description)> showExceptionCal
void Exception::showException([[maybe_unused]] const QString &title) const
{
if (showExceptionCallback)
showExceptionCallback(title, m_description);
showExceptionCallback(title, description());
}
void Exception::setShowExceptionCallback(std::function<void(QStringView, QStringView)> callback)
@@ -170,15 +76,7 @@ void Exception::setShowExceptionCallback(std::function<void(QStringView, QString
*/
int Exception::line() const
{
return m_line;
}
/*!
Returns the function name where this exception was thrown as a string.
*/
QString Exception::function() const
{
return m_function;
return location().line();
}
/*!
@@ -186,26 +84,25 @@ QString Exception::function() const
*/
QString Exception::file() const
{
return m_file;
return QString::fromUtf8(location().file_name());
}
QDebug operator<<(QDebug debug, const Exception &exception)
{
debug.nospace() << "Exception: " << exception.type() << "\n"
"Function: " << exception.function() << "\n"
"File: " << exception.file() << "\n"
"Line: " << exception.line() << "\n";
const auto &location = exception.location();
debug.nospace() << "Exception: " << exception.type()
<< "\n"
"Function: "
<< location.function_name()
<< "\n"
"File: "
<< location.file_name()
<< "\n"
"Line: "
<< location.line() << "\n";
if (!exception.description().isEmpty())
debug.nospace() << exception.description() << "\n";
if (!exception.backTrace().isEmpty())
debug.nospace().noquote() << exception.backTrace();
return debug.space();
}
/*!
\fn QString Exception::type() const
Returns the type of this exception as a string.
*/
}

View File

@@ -7,51 +7,39 @@
#include <QString>
#include <QCoreApplication>
/*!
\class QmlDesigner::InvalidArgumentException
\ingroup CoreExceptions
\brief The InvalidArgumentException class provides an exception for an invalid
argument.
*/
namespace QmlDesigner {
QString InvalidArgumentException::invalidArgumentDescription(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument)
{
if (QString::fromUtf8(function) == QLatin1String("createNode")) {
return DesignerCore::Tr::tr("Failed to create item of type %1.").arg(QString::fromUtf8(argument));
}
using namespace Qt::StringLiterals;
return Exception::defaultDescription(line, function, file);
QString InvalidArgumentException::invalidArgumentDescription(const Sqlite::source_location &location,
const QString &argument)
{
if (QLatin1StringView{location.file_name()} == "createNode"_L1)
return DesignerCore::Tr::tr("Failed to create item of type %1.").arg(argument);
return Exception::defaultDescription(location);
}
/*!
Constructs the exception for \a argument. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidArgumentException::InvalidArgumentException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument)
: InvalidArgumentException(line, function, file, argument,
invalidArgumentDescription(line, function, file, argument))
InvalidArgumentException::InvalidArgumentException(const QString &argument,
const Sqlite::source_location &location)
: Exception(location)
, m_argument{argument}
{
createWarning();
}
InvalidArgumentException::InvalidArgumentException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument,
const QString &description)
: Exception(line, function, file, description)
, m_argument(QString::fromUtf8(argument))
const char *InvalidArgumentException::what() const noexcept
{
createWarning();
return "InvalidArgumentException";
}
QString InvalidArgumentException::description() const
{
if (QLatin1StringView{location().file_name()} == "createNode"_L1)
return DesignerCore::Tr::tr("Failed to create item of type %1.").arg(m_argument);
return Exception::defaultDescription(location());
}
/*!
@@ -59,7 +47,7 @@ InvalidArgumentException::InvalidArgumentException(int line,
*/
QString InvalidArgumentException::type() const
{
return QLatin1String("InvalidArgumentException");
return "InvalidArgumentException"_L1;
}
/*!

View File

@@ -1,53 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalididexception.h"
#include <designercoretr.h>
#include <QCoreApplication>
namespace QmlDesigner {
static QString descriptionBasedOnReason(InvalidIdException::Reason reason)
{
if (reason == InvalidIdException::InvalidCharacters)
return DesignerCore::Tr::tr("Only alphanumeric characters and underscore allowed.\n"
"Ids must begin with a lowercase letter.");
return DesignerCore::Tr::tr("Ids have to be unique.");
}
static QString decorateDescriptionWithId(const QString &id, const QString &description)
{
return DesignerCore::Tr::tr("Invalid Id: %1\n%2").arg(id, description);
}
InvalidIdException::InvalidIdException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &id,
Reason reason)
: InvalidArgumentException(line, function, file, "id",
decorateDescriptionWithId(QString::fromUtf8(id),
descriptionBasedOnReason(reason)))
{ }
InvalidIdException::InvalidIdException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &id,
const QByteArray &description)
: InvalidArgumentException(line, function, file, "id",
decorateDescriptionWithId(QString::fromUtf8(id),
QString::fromUtf8(description)))
{
createWarning();
}
QString InvalidIdException::type() const
{
return QLatin1String("InvalidIdException");
}
}

View File

@@ -3,34 +3,27 @@
#include "invalidmetainfoexception.h"
/*!
\class QmlDesigner::InvalidMetaInfoException
\ingroup CoreExceptions
\brief The InvalidMetaInfoException class provides an exception for invalid meta
info.
\see NodeMetaInfo PropertyMetaInfo MetaInfo
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidMetaInfoException::InvalidMetaInfoException(int line,
const QByteArray &function,
const QByteArray &file)
: Exception(line, function, file)
using namespace Qt::StringLiterals;
InvalidMetaInfoException::InvalidMetaInfoException(const Sqlite::source_location &location)
: Exception(location)
{
createWarning();
}
QString InvalidMetaInfoException::description() const
{
return defaultDescription(location());
}
/*!
Returns the type of this exception as a string.
*/
QString InvalidMetaInfoException::type() const
{
return QLatin1String("InvalidMetaInfoException");
return "InvalidMetaInfoException"_L1;
}
}

View File

@@ -1,36 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalidmodelnodeexception.h"
/*!
\class QmlDesigner::InvalidModelNodeException
\ingroup CoreExceptions
\brief The InvalidModelNodeException class provides an exception for an invalid
model node.
\see ModelNode
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidModelNodeException::InvalidModelNodeException(int line,
const QByteArray &function,
const QByteArray &file)
: Exception(line, function, file)
{
createWarning();
}
/*!
Returns the type of this exception as a string.
*/
QString InvalidModelNodeException::type() const
{
return QLatin1String("InvalidModelNodeException");
}
}

View File

@@ -1,37 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalidmodelstateexception.h"
/*!
\class QmlDesigner::InvalidModelStateException
\ingroup CoreExceptions
\brief The InvalidModelStateException class provides an exception for an
invalid model state.
\see ModelState
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidModelStateException::InvalidModelStateException(int line,
const QByteArray &function,
const QByteArray &file)
: Exception(line, function, file)
{
createWarning();
}
/*!
Returns the type of the exception as a string.
*/
QString InvalidModelStateException::type() const
{
return QLatin1String("InvalidModelStateException");
}
} // namespace QmlDesigner

View File

@@ -1,44 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalidpropertyexception.h"
/*!
\class QmlDesigner::InvalidPropertyException
\ingroup CoreExceptions
\brief The InvalidPropertyException class provides an exception for an invalid
property.
\see AbstractProperty
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidPropertyException::InvalidPropertyException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument)
: Exception(line, function, file), m_argument(QString::fromLatin1(argument))
{
createWarning();
}
/*!
Returns the type of this exception as a string.
*/
QString InvalidPropertyException::type() const
{
return QLatin1String("InvalidPropertyException");
}
/*!
Returns the argument of the property of this exception as a string.
*/
QString InvalidPropertyException::argument() const
{
return m_argument;
}
} // namespace QmlDesigner

View File

@@ -1,36 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalidqmlsourceexception.h"
/*!
\class QmlDesigner::InvalidQmlSourceException
\ingroup CoreExceptions
\brief The InvalidQmlSourceException class provides an exception for invalid QML
source code.
*/
namespace QmlDesigner {
/*!
Constructs an exception for \qmlSource. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidQmlSourceException::InvalidQmlSourceException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &qmlSource)
: Exception(line, function, file, QString::fromUtf8(qmlSource))
{
createWarning();
}
/*!
Returns the type of the exception as a string.
*/
QString InvalidQmlSourceException::type() const
{
return QLatin1String("InvalidQmlSourceException");
}
} // namespace QmlDesigner

View File

@@ -1,34 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalidreparentingexception.h"
/*!
\class QmlDesigner::InvalidReparentingException
\ingroup CoreExceptions
\brief The InvalidReparentingException class provides an exception for
invalid reparenting.
\see ModelNode
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidReparentingException::InvalidReparentingException(int line,
const QByteArray &function,
const QByteArray &file)
: Exception(line, function, file)
{
createWarning();
}
/*!
Returns the type of this exception as a string.
*/
QString InvalidReparentingException::type() const
{
return QLatin1String("InvalidReparentingException");
}
} // namespace QmlDesigner

View File

@@ -1,36 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "invalidslideindexexception.h"
/*!
\class QmlDesigner::InvalidSlideIndexException
\ingroup CoreExceptions
\brief The InvalidSlideIndexException class provides an exception for an invalid
index for a slide.
\see ModelNode
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
InvalidSlideIndexException::InvalidSlideIndexException(int line,
const QByteArray &function,
const QByteArray &file)
: Exception(line, function, file)
{
createWarning();
}
/*!
Returns the type of the exception as a string.
*/
QString InvalidSlideIndexException::type() const
{
return QLatin1String("InvalidSlideIndexException");
}
} // namespace QmlDesigner

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "notimplementedexception.h"
namespace QmlDesigner {
NotImplementedException::NotImplementedException(int line,
const QByteArray &function,
const QByteArray &file):
Exception(line, function, file)
{
}
QString NotImplementedException::type() const
{
return QLatin1String("NotImplementedException");
}
}

View File

@@ -1,36 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "removebasestateexception.h"
/*!
\class QmlDesigner::RemoveBaseStateException
\ingroup CoreExceptions
\brief The RemoveBaseStateException class provides an exception if you try
to remove a BaseState.
/see NodeState ModelState
*/
namespace QmlDesigner {
/*!
Constructs an exception. \a line uses the __LINE__ macro,
\a function uses the __FUNCTION__ or the Q_FUNC_INFO macro, and \a file uses
the __FILE__ macro.
*/
RemoveBaseStateException::RemoveBaseStateException(int line,
const QByteArray &function,
const QByteArray &file)
: Exception(line, function, file)
{
createWarning();
}
/*!
Returns the type of this exception as a string.
*/
QString RemoveBaseStateException::type() const
{
return QLatin1String("RemoveBaseStateException");
}
} // namespace QmlDesigner

View File

@@ -3,25 +3,38 @@
#include "rewritingexception.h"
using namespace QmlDesigner;
namespace QmlDesigner {
RewritingException::RewritingException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &description,
const QString &documentTextContent)
: Exception(line, function, file, QString::fromUtf8(description))
using namespace Qt::StringLiterals;
RewritingException::RewritingException(const QString &description,
const QString &documentTextContent,
const Sqlite::source_location &location)
: Exception(location)
, m_description{description}
, m_documentTextContent(documentTextContent)
{
createWarning();
}
const char *RewritingException::what() const noexcept
{
return "RewritingException";
}
QString RewritingException::description() const
{
return defaultDescription(location()) + ": " + m_description;
}
QString RewritingException::type() const
{
return QLatin1String("RewritingException");
return "RewritingException"_L1;
}
QString RewritingException::documentTextContent() const
{
return m_documentTextContent;
}
} // namespace QmlDesigner

View File

@@ -5,55 +5,40 @@
#include <qmldesignercorelib_global.h>
#include <sqliteexception.h>
#include <QString>
#include <QDebug>
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT Exception
class QMLDESIGNERCORE_EXPORT Exception : public Sqlite::Exception
{
public:
Exception(int line,
const QByteArray &function,
const QByteArray &file);
virtual ~Exception();
virtual QString type() const = 0;
QString description() const;
virtual QString description() const = 0;
void showException(const QString &title = QString()) const;
static void setShowExceptionCallback(
std::function<void(QStringView title, QStringView description)> callback);
int line() const;
QString function() const;
QString file() const;
QString backTrace() const;
void createWarning() const;
static void setShouldAssert(bool assert);
static bool shouldAssert();
static void setWarnAboutException(bool warn);
static bool warnAboutException();
friend QDebug operator<<(QDebug debug, const Exception &exception);
protected:
Exception(int line,
const QByteArray &function,
const QByteArray &file,
const QString &description);
static QString defaultDescription(int line, const QByteArray &function, const QByteArray &file);
QString defaultDescription();
Exception(const Sqlite::source_location &location = Sqlite::source_location::current())
: Sqlite::Exception{location}
{}
static QString defaultDescription(const Sqlite::source_location &sourceLocation);
void createWarning() const;
private:
const int m_line;
const QString m_function;
const QString m_file;
const QString m_description;
const QString m_backTrace;
static bool s_shouldAssert;
static bool s_warnAboutException;
};
QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const Exception &exception);
}

View File

@@ -11,24 +11,20 @@ namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidArgumentException : public Exception
{
public:
InvalidArgumentException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument);
InvalidArgumentException(
const QString &argument,
const Sqlite::source_location &location = Sqlite::source_location::current());
const char *what() const noexcept override;
QString description() const override;
QString type() const override;
QString argument() const;
protected:
InvalidArgumentException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument,
const QString &description);
static QString invalidArgumentDescription(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument);
static QString invalidArgumentDescription(const Sqlite::source_location &location,
const QString &argument);
private:
const QString m_argument;
};

View File

@@ -1,30 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "invalidargumentexception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidIdException : public InvalidArgumentException
{
public:
enum Reason { InvalidCharacters, DuplicateId };
InvalidIdException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &id,
Reason reason);
InvalidIdException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &id,
const QByteArray &description);
QString type() const override;
};
}

View File

@@ -10,10 +10,10 @@ namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidMetaInfoException : public Exception
{
public:
InvalidMetaInfoException(int line,
const QByteArray &function,
const QByteArray &file);
InvalidMetaInfoException(
const Sqlite::source_location &location = Sqlite::source_location::current());
QString description() const override;
QString type() const override;
};

View File

@@ -1,21 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "exception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidModelNodeException : public Exception
{
public:
InvalidModelNodeException(int line,
const QByteArray &function,
const QByteArray &file);
QString type() const override;
};
}

View File

@@ -1,21 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "exception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidModelStateException : public Exception
{
public:
InvalidModelStateException(int line,
const QByteArray &function,
const QByteArray &file);
QString type() const override;
};
} // namespace QmlDesigner

View File

@@ -1,25 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "exception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidPropertyException : public Exception
{
public:
InvalidPropertyException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &argument);
QString type() const override;
QString argument() const;
private:
const QString m_argument;
};
} // namespace QmlDesigner

View File

@@ -1,21 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <exception.h>
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidQmlSourceException : public QmlDesigner::Exception
{
public:
InvalidQmlSourceException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &qmlSource = QByteArray());
QString type() const override;
};
} // namespace QmlDesigner

View File

@@ -1,20 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "exception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidReparentingException : public Exception
{
public:
InvalidReparentingException(int line,
const QByteArray &function,
const QByteArray &file);
QString type() const override;
};
} // namespace QmlDesigner

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "exception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT InvalidSlideIndexException : public Exception
{
public:
InvalidSlideIndexException(int line,
const QByteArray &function,
const QByteArray &file);
QString type() const override;
};
} // namespace QmlDesigner

View File

@@ -10,7 +10,6 @@
#include <QString>
#include "qmldesignercorelib_global.h"
#include "invalidmetainfoexception.h"
QT_BEGIN_NAMESPACE
class QDeclarativeContext;

View File

@@ -1,21 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "exception.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT NotImplementedException : public Exception
{
public:
NotImplementedException(int line,
const QByteArray &function,
const QByteArray &file);
QString type() const override;
};
}

View File

@@ -1,20 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <exception.h>
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT RemoveBaseStateException : public Exception
{
public:
RemoveBaseStateException(int line,
const QByteArray &function,
const QByteArray &file);
QString type() const override;
};
} // namespace QmlDesigner

View File

@@ -10,17 +10,19 @@ namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT RewritingException: public Exception
{
public:
RewritingException(int line,
const QByteArray &function,
const QByteArray &file,
const QByteArray &description,
const QString &documentTextContent);
RewritingException(const QString &description,
const QString &documentTextContent,
const Sqlite::source_location &location = Sqlite::source_location::current());
const char *what() const noexcept override;
QString description() const override;
QString type() const override;
QString documentTextContent() const;
private:
const QString m_documentTextContent;
QString m_description;
QString m_documentTextContent;
};
} // namespace QmlDesigner

View File

@@ -5,7 +5,6 @@
#include "nodemetainfo.h"
#include "qregularexpression.h"
#include <invalidmetainfoexception.h>
#include <propertycontainer.h>
#include <sourcepathcache.h>

View File

@@ -46,7 +46,7 @@ void ItemLibraryInfo::addEntries(const QList<ItemLibraryEntry> &entries, bool ov
for (const ItemLibraryEntry &entry : entries) {
const QString key = keyForEntry(entry);
if (!overwriteDuplicate && m_nameToEntryHash.contains(key))
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
throw InvalidMetaInfoException();
m_nameToEntryHash.insert(key, entry);
}
emit entriesChanged();

View File

@@ -46,14 +46,14 @@ void MetaInfoReader::readMetaInfoFile(const QString &path, bool overwriteDuplica
qWarning() << "readMetaInfoFile()" << path;
qWarning() << errors();
m_parserState = Error;
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
throw InvalidMetaInfoException();
}
if (!errors().isEmpty()) {
qWarning() << "readMetaInfoFile()" << path;
qWarning() << errors();
m_parserState = Error;
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
throw InvalidMetaInfoException();
}
syncItemLibraryEntries();
}

View File

@@ -34,23 +34,6 @@ QT_WARNING_DISABLE_MSVC(4996)
namespace QmlDesigner {
/*!
\class QmlDesigner::NodeMetaInfo
\ingroup CoreModel
\brief The NodeMetaInfo class provides meta information about a qml type.
A NodeMetaInfo object can be created via ModelNode::metaInfo, or MetaInfo::nodeMetaInfo.
The object can be invalid - you can check this by calling isValid().
The object is invalid if you ask for meta information for
an non-existing qml property. Also the node meta info can become invalid
if the enclosing type is deregistered from the meta type system (e.g.
a sub component qml file is deleted). Trying to call any accessor functions on an invalid
NodeMetaInfo object will result in an InvalidMetaInfoException being thrown.
\see QmlDesigner::MetaInfo, QmlDesigner::PropertyMetaInfo, QmlDesigner::EnumeratorMetaInfo
*/
namespace {
using Storage::ModuleKind;

View File

@@ -915,11 +915,7 @@ void ModelPrivate::resetModelByRewriter(const QString &description)
if (m_rewriterView) {
m_rewriterView->resetToLastCorrectQml();
throw RewritingException(__LINE__,
__FUNCTION__,
__FILE__,
description.toUtf8(),
rewriterView()->textModifierContent());
throw RewritingException(description, rewriterView()->textModifierContent());
}
}

View File

@@ -3,9 +3,6 @@
#include "nodeabstractproperty.h"
#include "nodeproperty.h"
#include "invalidmodelnodeexception.h"
#include "invalidpropertyexception.h"
#include "invalidreparentingexception.h"
#include "internalnodeabstractproperty.h"
#include "internalnode_p.h"
#include "model.h"

View File

@@ -480,11 +480,7 @@ void RewriterView::applyChanges()
qDebug().noquote() << "RewriterView::applyChanges() got called while in error state. Will "
"do a quick-exit now.";
qDebug().noquote() << "Content: " << content;
throw RewritingException(__LINE__,
__FUNCTION__,
__FILE__,
"RewriterView::applyChanges() already in error state",
content);
throw RewritingException("RewriterView::applyChanges() already in error state", content);
}
m_differenceHandling = Validate;
@@ -508,11 +504,7 @@ void RewriterView::applyChanges()
qDebug().noquote() << "Content: " << content;
if (!errors().isEmpty())
qDebug().noquote() << "Error:" << errors().constFirst().description();
throw RewritingException(__LINE__,
__FUNCTION__,
__FILE__,
qPrintable(m_rewritingErrorMessage),
content);
throw RewritingException(m_rewritingErrorMessage, content);
}
}

View File

@@ -233,12 +233,6 @@ static bool documentIsAlreadyOpen(DesignDocument *designDocument, Core::IEditor
&& designDocument->fileName() == editor->document()->filePath();
}
static bool shouldAssertInException()
{
QProcessEnvironment processEnvironment = QProcessEnvironment::systemEnvironment();
return !processEnvironment.value("QMLDESIGNER_ASSERT_ON_EXCEPTION").isEmpty();
}
static bool warningsForQmlFilesInsteadOfUiQmlEnabled()
{
return QmlDesignerPlugin::settings().value(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES).toBool();
@@ -247,18 +241,6 @@ static bool warningsForQmlFilesInsteadOfUiQmlEnabled()
QmlDesignerPlugin::QmlDesignerPlugin()
{
m_instance = this;
// Exceptions should never ever assert: they are handled in a number of
// places where it is actually VALID AND EXPECTED BEHAVIOUR to get an
// exception.
// If you still want to see exactly where the exception originally
// occurred, then you have various ways to do this:
// 1. set a breakpoint on the constructor of the exception
// 2. in gdb: "catch throw" or "catch throw Exception"
// 3. set a breakpoint on __raise_exception()
// And with gdb, you can even do this from your ~/.gdbinit file.
// DnD is not working with gdb so this is still needed to get a good stacktrace
Exception::setShouldAssert(shouldAssertInException());
}
QmlDesignerPlugin::~QmlDesignerPlugin()

View File

@@ -4,7 +4,6 @@
#include "qml3dnode.h"
#include "auxiliarydataproperties.h"
#include "bindingproperty.h"
#include "invalidmodelnodeexception.h"
#include "nodehints.h"
#include "nodelistproperty.h"
#include "qmlanchors.h"

View File

@@ -19,7 +19,6 @@
#include <auxiliarydataproperties.h>
#include <designersettings.h>
#include <invalidmodelnodeexception.h>
#include <qmltimeline.h>

View File

@@ -5,7 +5,6 @@
#include "abstractview.h"
#include <nodelistproperty.h>
#include <variantproperty.h>
#include <invalidmodelnodeexception.h>
#include "bindingproperty.h"
#include "qmlchangeset.h"
#include "qmlitemnode.h"

View File

@@ -8,7 +8,6 @@
#include "qmltimelinekeyframegroup.h"
#include <auxiliarydataproperties.h>
#include <invalidmodelnodeexception.h>
#include <nodelistproperty.h>
#include <variantproperty.h>

View File

@@ -7,7 +7,6 @@
#include "qmlitemnode.h"
#include <auxiliarydataproperties.h>
#include <invalidmodelnodeexception.h>
#include <nodelistproperty.h>
#include <variantproperty.h>

View File

@@ -5,8 +5,6 @@
#include <designersettings.h>
#include <externaldependenciesinterface.h>
#include <invalididexception.h>
#include <invalidmodelnodeexception.h>
#include <model.h>
#include <modelmerger.h>
#include <modelnode.h>

View File

@@ -69,16 +69,7 @@ extend_qtc_library(TestDesignerCore
SOURCES
exception.cpp
invalidargumentexception.cpp
invalididexception.cpp
invalidmetainfoexception.cpp
invalidmodelnodeexception.cpp
invalidmodelstateexception.cpp
invalidpropertyexception.cpp
invalidqmlsourceexception.cpp
invalidreparentingexception.cpp
invalidslideindexexception.cpp
notimplementedexception.cpp
removebasestateexception.cpp
rewritingexception.cpp
)
@@ -192,14 +183,7 @@ extend_qtc_library(TestDesignerCore
imagecacheauxiliarydata.h
import.h
invalidargumentexception.h
invalididexception.h
invalidmetainfoexception.h
invalidmodelnodeexception.h
invalidmodelstateexception.h
invalidpropertyexception.h
invalidqmlsourceexception.h
invalidreparentingexception.h
invalidslideindexexception.h
iwidgetplugin.h
mathutils.h
modelfwd.h
@@ -211,7 +195,6 @@ extend_qtc_library(TestDesignerCore
nodelistproperty.h
nodemetainfo.h
nodeproperty.h
notimplementedexception.h
objectpropertybinding.h
projectstorageids.h
propertybinding.h
@@ -222,7 +205,6 @@ extend_qtc_library(TestDesignerCore
qmldesignercorelib_exports.h
qmldesignercorelib_global.h
qmldesignercoreconstants.h
removebasestateexception.h
rewritertransaction.h
rewritingexception.h
signalhandlerproperty.h