Skip to content

Commit 773dcb1

Browse files
authored
Include records.yaml line and column in the logs when error is found. (#12267)
For instance, with the following config: records: http: per_server: connection: match: both*ioajs new: field: 11: We will get a warning log with the line and the column from the records.yaml file exactly where the error was detected. In the above example, match and new.field have different sort of errors but both now log the line+column. WARNING: We have found the following issues when reading the records node: Warn: Warn: proxy.config.http.per_server.connection.match - Validity Check error at line=37, col=9. Pattern '^(?:ip|host|both|none)$' failed against 'both*ioajs'. Default value will be used Warn: Ignoring field 'field' [proxy.config.http.per_server.connection.new.field] at line=39, col=11. Not registered and Unknown tag type '?
1 parent 6a6db7b commit 773dcb1

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

include/records/RecYAMLDefs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ struct CfgNode {
8383
}
8484
}
8585

86+
std::string
87+
mark_as_view(swoc::TextView fmt = "Line: {}, Column: {}") const
88+
{
89+
swoc::LocalBufferWriter<128> lbw;
90+
lbw.print(fmt, node.Mark().line + 1, node.Mark().column + 1);
91+
std::string mark;
92+
mark.reserve(lbw.view().size());
93+
mark = std::string{lbw.view().data(), lbw.view().size()};
94+
return mark;
95+
}
8696
// public
8797
YAML::Node node;
8898
YAML::Node value_node;

src/records/RecYAMLDecoder.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ SetRecordFromYAMLNode(CfgNode const &field, swoc::Errata &errata)
131131
// we ignore it.
132132
auto [dtype, e] = detail::try_deduce_type(field.value_node);
133133
if (!e.empty()) {
134-
errata.note(ERRATA_WARN, "Ignoring field '{}' [{}] at Line {}. Not registered and {}", field.node.as<std::string>(),
135-
field.get_record_name(), field.node.Mark().line + 1, e);
134+
errata.note(ERRATA_WARN, "Ignoring field '{}' [{}] at {}. Not registered and {}", field.node.as<std::string>(),
135+
field.get_record_name(), field.mark_as_view("line={}, col={}"), e);
136136
// We can't continue without knowing the type.
137137
return;
138138
}
@@ -164,8 +164,8 @@ SetRecordFromYAMLNode(CfgNode const &field, swoc::Errata &errata)
164164
}
165165

166166
if (!check_expr.empty() && RecordValidityCheck(value_str.c_str(), check_type, check_expr.c_str()) == false) {
167-
errata.note(ERRATA_WARN, "{} - Validity Check failed. '{}' against '{}'. Default value will be used", record_name, check_expr,
168-
value_str);
167+
errata.note(ERRATA_WARN, "{} - Validity Check error {}. Pattern '{}' failed against '{}'. Default value will be used",
168+
record_name, field.mark_as_view("at line={}, col={}"), check_expr, value_str);
169169
return;
170170
}
171171

0 commit comments

Comments
 (0)