diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-12-17 06:35:10 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-17 06:35:10 -0500 |
| commit | 2c7e0e7cb4d8bf5c51f22968a5ffd2366d6bcdf2 (patch) | |
| tree | 8b1b903e524d1747b8b2a26a94ba383ac7ab7d90 /src/loot.cpp | |
| parent | c9d33dad4667e6087ced5155805e88984cc6b3fd (diff) | |
| parent | ca6f9990c691a5d20e2b8d97ad98e4ad80c13a9e (diff) | |
Merge pull request #941 from isanae/loot-errors
Loot errors
Diffstat (limited to 'src/loot.cpp')
| -rw-r--r-- | src/loot.cpp | 124 |
1 files changed, 102 insertions, 22 deletions
diff --git a/src/loot.cpp b/src/loot.cpp index a86cdcff..3feb95c9 100644 --- a/src/loot.cpp +++ b/src/loot.cpp @@ -231,11 +231,31 @@ log::Levels levelFromLoot(lootcli::LogLevels level) } } - QString Loot::Report::toMarkdown() const { QString s; + if (!okay) { + s += "## " + tr("Loot failed to run") + "\n"; + + if (errors.empty() && warnings.empty()) { + s += tr("No errors were reported. The log below might have more information.\n"); + } + } + + s += errorsMarkdown(); + + if (okay) { + s += "\n" + successMarkdown(); + } + + return s; +} + +QString Loot::Report::successMarkdown() const +{ + QString s; + if (!messages.empty()) { s += "### " + QObject::tr("General messages") + "\n"; @@ -268,6 +288,33 @@ QString Loot::Report::toMarkdown() const return s; } +QString Loot::Report::errorsMarkdown() const +{ + QString s; + + if (!errors.empty()) { + s += "### " + tr("Errors") + ":\n"; + + for (auto&& e : errors) { + s += " - " + e + "\n"; + } + } + + if (!warnings.empty()) { + if (!s.isEmpty()) { + s += "\n"; + } + + s += "### " + tr("Warnings") + ":\n"; + + for (auto&& w : warnings) { + s += " - " + w + "\n"; + } + } + + return s; +} + QString Loot::Stats::toMarkdown() const { return QString("`stats: %1s, lootcli %2, loot %3`") @@ -396,20 +443,13 @@ Loot::~Loot() m_thread->wait(); } - if (QFile::exists(LootReportPath)) { - log::debug("deleting temporary loot report '{}'", LootReportPath); - const auto r = shell::Delete(LootReportPath); - - if (!r) { - log::error( - "failed to remove temporary loot json report '{}': {}", - LootReportPath, r.toString()); - } - } + deleteReportFile(); } bool Loot::start(QWidget* parent, bool didUpdateMasterList) { + deleteReportFile(); + log::debug("starting loot"); m_pipe.reset(new AsyncPipe); @@ -506,6 +546,16 @@ const Loot::Report& Loot::report() const return m_report; } +const std::vector<QString>& Loot::errors() const +{ + return m_errors; +} + +const std::vector<QString>& Loot::warnings() const +{ + return m_warnings; +} + void Loot::lootThread() { try @@ -514,8 +564,9 @@ void Loot::lootThread() if (waitForCompletion()) { m_result = true; - processOutputFile(); } + + m_report = createReport(); } catch(...) { @@ -624,7 +675,15 @@ void Loot::processMessage(const lootcli::Message& m) { case lootcli::MessageType::Log: { - emit log(levelFromLoot(m.logLevel), QString::fromStdString(m.log)); + const auto level = levelFromLoot(m.logLevel); + + if (level == log::Error) { + m_errors.push_back(QString::fromStdString(m.log)); + } else if (level == log::Warning) { + m_warnings.push_back(QString::fromStdString(m.log)); + } + + emit log(level, QString::fromStdString(m.log)); break; } @@ -636,7 +695,36 @@ void Loot::processMessage(const lootcli::Message& m) } } -void Loot::processOutputFile() +Loot::Report Loot::createReport() const +{ + Report r; + + r.okay = m_result; + r.errors = m_errors; + r.warnings = m_warnings; + + if (m_result) { + processOutputFile(r); + } + + return r; +} + +void Loot::deleteReportFile() +{ + if (QFile::exists(LootReportPath)) { + log::debug("deleting temporary loot report '{}'", LootReportPath); + const auto r = shell::Delete(LootReportPath); + + if (!r) { + log::error( + "failed to remove temporary loot json report '{}': {}", + LootReportPath, r.toString()); + } + } +} + +void Loot::processOutputFile(Report& r) const { log::debug("parsing json output file at '{}'", LootReportPath); @@ -661,21 +749,13 @@ void Loot::processOutputFile() return; } - m_report = createReport(doc); -} - -Loot::Report Loot::createReport(const QJsonDocument& doc) const -{ requireObject(doc, "root"); - Report r; const QJsonObject object = doc.object(); r.messages = reportMessages(getOpt<QJsonArray>(object, "messages")); r.plugins = reportPlugins(getOpt<QJsonArray>(object, "plugins")); r.stats = reportStats(getWarn<QJsonObject>(object, "stats")); - - return r; } std::vector<Loot::Plugin> Loot::reportPlugins(const QJsonArray& plugins) const |
