2026-09-08 16:54:21 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2026-07-18 18:48:23 +02:00
|
|
|
#include "error.h"
|
|
|
|
|
#include "show.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "file.h"
|
|
|
|
|
|
|
|
|
|
bool display_source(const std::string& filename_arg)
|
|
|
|
|
{
|
|
|
|
|
if (filename_arg.empty()) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
fs::path filename = fs::path(filename_arg).filename();
|
|
|
|
|
return sks_commands.count(filename) == 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-08 16:54:21 +02:00
|
|
|
std::string Error::message(const std::string& epilog) const
|
2026-07-18 18:48:23 +02:00
|
|
|
{
|
2026-08-16 01:37:59 +02:00
|
|
|
// The separator is not cosmetic: the description ends with a sentence, and
|
|
|
|
|
// appending the advice straight onto it ran the two together into one word
|
|
|
|
|
// ("...for an unspecified targetkdiag loads no klammerset..."). m_desc is
|
|
|
|
|
// then justified to 80 columns, so the break has to be a blank line rather
|
|
|
|
|
// than a single newline, which justify() would fold back into the flow.
|
2026-09-08 16:54:21 +02:00
|
|
|
std::string desc = m_desc;
|
2026-08-16 01:37:59 +02:00
|
|
|
if (epilog != "") {
|
2026-09-08 16:54:21 +02:00
|
|
|
desc += "\n\n" + epilog + "\n";
|
2026-08-16 01:37:59 +02:00
|
|
|
}
|
2026-09-08 16:54:21 +02:00
|
|
|
std::stringstream ss {};
|
|
|
|
|
ss << command_name << " (" << m_type << " error)";
|
2026-07-18 18:48:23 +02:00
|
|
|
if (display_source(m_loc.m_filename)) {
|
2026-09-08 16:54:21 +02:00
|
|
|
ss << ":\n " << m_loc.m_filename;
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
if (m_loc.m_line > -1) {
|
2026-09-08 16:54:21 +02:00
|
|
|
ss << ", line " << m_loc.m_line;
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
|
|
|
|
if (m_loc.m_chr > -1) {
|
2026-09-08 16:54:21 +02:00
|
|
|
ss << ", character " << m_loc.m_chr + 1;
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|
2026-09-08 16:54:21 +02:00
|
|
|
ss << ":\n\n" << justify(desc, 80, 0);
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Error::print_message(const std::string& epilog)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "\n" << red << message(epilog) << reset << "\n";
|
2026-07-18 18:48:23 +02:00
|
|
|
}
|