Introduce macro to assert and return the assertion condition

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2026-01-21 17:45:12 +05:00
parent 9ac0314d7a
commit 490df18fd5
No known key found for this signature in database
GPG key ID: B77C34313AEE1FFF
3 changed files with 34 additions and 10 deletions

View file

@ -38,6 +38,8 @@
#include <QDebug>
#include "Assert.h"
Q_LOGGING_CATEGORY(taskLogC, "launcher.task")
Task::Task(bool show_debug) : m_show_debug(show_debug)
@ -96,9 +98,8 @@ void Task::start()
break;
}
case State::Running: {
if (m_show_debug)
if (ASSERT_NEVER(isRunning()) && m_show_debug)
qCWarning(taskLogC) << "The launcher tried to start task" << describe() << "while it was already running!";
Q_ASSERT(!isRunning());
return;
}
}
@ -111,9 +112,8 @@ void Task::start()
void Task::emitFailed(QString reason)
{
// Don't fail twice.
if (!isRunning()) {
if (ASSERT_NEVER(!isRunning())) {
qCCritical(taskLogC) << "Task" << describe() << "failed while not running!!!!: " << reason;
Q_ASSERT(!isRunning());
return;
}
m_state = State::Failed;
@ -126,9 +126,8 @@ void Task::emitFailed(QString reason)
void Task::emitAborted()
{
// Don't abort twice.
if (!isRunning()) {
if (ASSERT_NEVER(!isRunning())) {
qCCritical(taskLogC) << "Task" << describe() << "aborted while not running!!!!";
Q_ASSERT(!isRunning());
return;
}
m_state = State::AbortedByUser;
@ -142,9 +141,8 @@ void Task::emitAborted()
void Task::emitSucceeded()
{
// Don't succeed twice.
if (!isRunning()) {
if (ASSERT_NEVER(!isRunning())) {
qCCritical(taskLogC) << "Task" << describe() << "succeeded while not running!!!!";
Q_ASSERT(!isRunning());
return;
}
m_state = State::Succeeded;