Skip to content

Commit

Permalink
Limit the number of printed metadata file errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Mar 21, 2022
1 parent d1e90e7 commit d852563
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
25 changes: 18 additions & 7 deletions src/backend/providers/pegasus_metadata/PegasusMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@


namespace {
constexpr size_t ISSUE_LOG_LIMIT = 100;

QStringList tokenize_by_comma(const QString& str)
{
QStringList list = str.split(QLatin1Char(','), Qt::SkipEmptyParts);
Expand Down Expand Up @@ -162,19 +164,25 @@ Metadata::Metadata(QString log_tag)
, rx_uri(QStringLiteral("^[a-zA-Z][a-zA-Z0-9+\\-.]*:.+"))
{}

void Metadata::print_error(const ParserState& ps, const metafile::Error& err) const
void Metadata::print_error(ParserState& ps, const metafile::Error& err) const
{
Log::error(m_log_tag, LOGMSG("`%1`, line %2: %3")
.arg(::pretty_path(ps.path), QString::number(err.line), err.message));
ps.found_issues++;
if (ps.found_issues <= ISSUE_LOG_LIMIT) {
Log::error(m_log_tag, LOGMSG("`%1`, line %2: %3")
.arg(::pretty_path(ps.path), QString::number(err.line), err.message));
}
}

void Metadata::print_warning(const ParserState& ps, const metafile::Entry& entry, const QString& msg) const
void Metadata::print_warning(ParserState& ps, const metafile::Entry& entry, const QString& msg) const
{
Log::warning(m_log_tag, LOGMSG("`%1`, line %2: %3")
.arg(::pretty_path(ps.path), QString::number(entry.line), msg));
ps.found_issues++;
if (ps.found_issues <= ISSUE_LOG_LIMIT) {
Log::warning(m_log_tag, LOGMSG("`%1`, line %2: %3")
.arg(::pretty_path(ps.path), QString::number(entry.line), msg));
}
}

const QString& Metadata::first_line_of(const ParserState& ps, const metafile::Entry& entry) const
const QString& Metadata::first_line_of(ParserState& ps, const metafile::Entry& entry) const
{
Q_ASSERT(!entry.key.isEmpty());
Q_ASSERT(!entry.values.empty());
Expand Down Expand Up @@ -551,6 +559,9 @@ std::vector<FileFilter> Metadata::apply_metafile(const QString& metafile_path, S
Log::error(m_log_tag, LOGMSG("Failed to read metadata file `%1`")
.arg(::pretty_path(metafile_path)));
}
if (ps.found_issues > ISSUE_LOG_LIMIT) {
Log::warning(m_log_tag, LOGMSG("%1 other issues omitted").arg(QString::number(ps.found_issues - ISSUE_LOG_LIMIT)));
}

return std::move(ps.filters);
}
Expand Down
7 changes: 4 additions & 3 deletions src/backend/providers/pegasus_metadata/PegasusMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ParserState {
model::Collection* cur_coll = nullptr;
std::vector<FileFilter> filters;
std::vector<model::Collection*> all_colls;
size_t found_issues = 0;

explicit ParserState(const QString&);
NO_COPY_NO_MOVE(ParserState)
Expand Down Expand Up @@ -77,10 +78,10 @@ class Metadata {
const QRegularExpression rx_uri;


void print_error(const ParserState& ps, const metafile::Error&) const;
void print_warning(const ParserState& ps, const metafile::Entry&, const QString&) const;
void print_error(ParserState&, const metafile::Error&) const;
void print_warning(ParserState&, const metafile::Entry&, const QString&) const;

const QString& first_line_of(const ParserState& ps, const metafile::Entry&) const;
const QString& first_line_of(ParserState&, const metafile::Entry&) const;
void replace_newlines(QString&) const;

void apply_collection_entry(ParserState&, const metafile::Entry&) const;
Expand Down

0 comments on commit d852563

Please sign in to comment.