An error inside a klammer is reported at your document; the image search path
Assembled from development commit 632297b7657a. Since 1b00738: when something
goes wrong while a klammer is being applied, the report begins with the
line of your document that applied it, then lists the klammers being
applied and where inside the klammer set the fault was raised; the
Python binding's line and column are the application's too. The default
image search path is the document's directory, imgsrc beside it and
../imgsrc, and a not-found report shows exactly those.
This commit is contained in:
1 parent
1b00738654
commit
5c29da52dc
9 files changed
+135
-15
No files matched your search
+60
-7
@@ -15,6 +15,23 @@ bool display_source(const std::string& filename_arg)
|
||||
}
|
||||
}
|
||||
|
||||
// "file, line N, character M" for a location, under the same rule as the
|
||||
// headline: the file only when display_source() says so.
|
||||
static std::string where(const Locator& loc)
|
||||
{
|
||||
std::stringstream ss {};
|
||||
if (display_source(loc.m_filename)) {
|
||||
ss << loc.m_filename;
|
||||
}
|
||||
if (loc.m_line > -1) {
|
||||
ss << (ss.str().empty() ? "line " : ", line ") << loc.m_line;
|
||||
}
|
||||
if (loc.m_chr > -1) {
|
||||
ss << ", character " << loc.m_chr + 1;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Error::message(const std::string& epilog) const
|
||||
{
|
||||
// The separator is not cosmetic: the description ends with a sentence, and
|
||||
@@ -28,16 +45,52 @@ std::string Error::message(const std::string& epilog) const
|
||||
}
|
||||
std::stringstream ss {};
|
||||
ss << command_name << " (" << m_type << " error)";
|
||||
if (display_source(m_loc.m_filename)) {
|
||||
ss << ":\n " << m_loc.m_filename;
|
||||
// The headline is location(): the outermost application when the error
|
||||
// escaped through klammer applications, which is the user's document.
|
||||
const Locator& head = location();
|
||||
if (display_source(head.m_filename)) {
|
||||
ss << ":\n " << head.m_filename;
|
||||
}
|
||||
if (m_loc.m_line > -1) {
|
||||
ss << ", line " << m_loc.m_line;
|
||||
if (head.m_line > -1) {
|
||||
ss << ", line " << head.m_line;
|
||||
}
|
||||
if (m_loc.m_chr > -1) {
|
||||
ss << ", character " << m_loc.m_chr + 1;
|
||||
if (head.m_chr > -1) {
|
||||
ss << ", character " << head.m_chr + 1;
|
||||
}
|
||||
ss << ":\n\n" << justify(desc, 80, 0);
|
||||
ss << ":\n\n";
|
||||
// Then the chain, outermost first, each level saying which klammer was
|
||||
// applied and, below the top, where; last, where the error itself was
|
||||
// raised when that is not the innermost application. Lines begin with
|
||||
// two spaces so justify() keeps them verbatim. A recursion error
|
||||
// carries hundreds of levels: the outermost, an ellipsis and the two
|
||||
// innermost say what a person needs.
|
||||
if (!m_applications.empty()) {
|
||||
const std::size_t n = m_applications.size();
|
||||
auto level = [&](std::size_t i, bool with_place) { // i: 0 = innermost
|
||||
ss << " applying @" << m_applications[i].first;
|
||||
if (with_place) {
|
||||
ss << " at " << where(m_applications[i].second);
|
||||
}
|
||||
ss << "\n";
|
||||
};
|
||||
level(n - 1, false);
|
||||
if (n > 4) {
|
||||
ss << " ... " << n - 3 << " applications ...\n";
|
||||
level(1, true);
|
||||
level(0, true);
|
||||
} else {
|
||||
for (std::size_t i = n - 1; i-- > 0; ) {
|
||||
level(i, true);
|
||||
}
|
||||
}
|
||||
const Locator& inner = m_applications.front().second;
|
||||
if (m_loc.m_filename != inner.m_filename || m_loc.m_line != inner.m_line
|
||||
|| m_loc.m_chr != inner.m_chr) {
|
||||
ss << " at " << where(m_loc) << "\n";
|
||||
}
|
||||
ss << "\n";
|
||||
}
|
||||
ss << justify(desc, 80, 0);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "locator.h"
|
||||
|
||||
@@ -27,9 +29,22 @@ public:
|
||||
std::string message(const std::string& epilog="") const;
|
||||
void print_message(const std::string& epilog="");
|
||||
|
||||
// Where the error is reported: the OUTERMOST klammer application it
|
||||
// escaped through when there is one -- the place in the user's document
|
||||
// -- else where it was raised. The commands' report headlines this and
|
||||
// the Python binding's line/column are this (2026-09-25; before, an
|
||||
// error raised inside a klammer's body, such as an @eval in
|
||||
// sks/image/image.k, was located there and the document never named).
|
||||
const Locator& location() const
|
||||
{ return m_applications.empty() ? m_loc : m_applications.back().second; }
|
||||
|
||||
std::string m_type {};
|
||||
std::string m_desc {};
|
||||
Locator m_loc; // {};
|
||||
// The klammer applications the error escaped through, innermost first:
|
||||
// (name, where applied). Filled by Machine::apply_klammer_registry as
|
||||
// the exception unwinds; message() prints the chain after the headline.
|
||||
std::vector<std::pair<std::string, Locator>> m_applications {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
+11
-1
@@ -857,7 +857,17 @@ void Machine::apply_klammer_registry(
|
||||
{
|
||||
(void)K::log(3, "Klammer");
|
||||
std::string name = trim_char(begin->m_text, '@');
|
||||
katom_list applied_katoms = apply_klammer(klammer_registry.m_klammers[name], target, begin, end);
|
||||
katom_list applied_katoms {};
|
||||
try {
|
||||
applied_katoms = apply_klammer(klammer_registry.m_klammers[name], target, begin, end);
|
||||
} catch (Error& e) {
|
||||
// The error escapes through this application: record it, so that the
|
||||
// report can headline the user's document and show the chain, then
|
||||
// let it go on unwinding (the exception object itself is what the
|
||||
// outer handlers and the commands see).
|
||||
e.m_applications.emplace_back(name, begin->m_loc);
|
||||
throw;
|
||||
}
|
||||
for (auto& k : applied_katoms) {
|
||||
if (k.m_type == katom_t::bar || k.m_type == katom_t::double_bar || k.m_type == katom_t::option_name) {
|
||||
k.m_type = katom_t::text;
|
||||
|
||||
Reference in new issue
Block a user