[loader] add some help text to the error for values without a corresponding capture

This commit is contained in:
Tim Stack 2022-08-16 22:39:24 -07:00
parent 001f26d066
commit 74c2237296
2 changed files with 22 additions and 1 deletions

View File

@ -1904,6 +1904,8 @@ external_log_format::build(std::vector<lnav::console::user_message>& errors)
}
if (this->elf_type == elf_type_t::ELF_TYPE_TEXT) {
std::set<std::string> available_captures;
bool found_in_pattern = false;
for (const auto& pat : this->elf_patterns) {
auto cap_index = pat.second->p_pcre->name_index(
@ -1912,8 +1914,20 @@ external_log_format::build(std::vector<lnav::console::user_message>& errors)
found_in_pattern = true;
break;
}
for (auto name_iter = pat.second->p_pcre->named_begin();
name_iter != pat.second->p_pcre->named_end();
++name_iter)
{
available_captures.insert(name_iter->pnc_name);
}
}
if (!found_in_pattern) {
auto notes
= attr_line_t("the following captures are available:\n ")
.join(available_captures,
VC_ROLE.value(role_t::VCR_SYMBOL),
", ");
errors.emplace_back(
lnav::console::user_message::error(
attr_line_t("invalid value ")
@ -1924,7 +1938,11 @@ external_log_format::build(std::vector<lnav::console::user_message>& errors)
.with_reason(
attr_line_t("no patterns have a capture named ")
.append_quoted(vd->vd_meta.lvm_name.get()))
.with_snippets(this->get_snippets()));
.with_note(notes)
.with_snippets(this->get_snippets())
.with_help("values are populated from captures in "
"patterns, so at least one pattern must "
"have a capture with this value name"));
}
}

View File

@ -101,6 +101,9 @@
✘ error: invalid value “/invalid_props_log/value/non-existent”
reason: no patterns have a capture named “non-existent”
 --> {test_dir}/bad-config/formats/invalid-properties/format.json:4
 = note: the following captures are available:
body, pid, timestamp
 = help: values are populated from captures in patterns, so at least one pattern must have a capture with this value name
✘ error: invalid value for property “/invalid_props_log/timestamp-field”
reason: “ts” was not found in the pattern at /invalid_props_log/regex/std
 --> {test_dir}/bad-config/formats/invalid-properties/format.json:4