aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sadie Powell2025-11-30 12:37:04 +0000
committerGravatar Sadie Powell2025-11-30 12:37:04 +0000
commit54428606dba78a266bad420a5fdeca3ef3211ac7 (patch)
treec5189d8f0fb2ac0866b174a6c3f6d47af9a600bb
parentFix genssl with newer versions of GnuTLS. (diff)
Make errors from the config parser more detailed.
-rw-r--r--src/configparser.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp
index 1055cbbd5..3bde640d6 100644
--- a/src/configparser.cpp
+++ b/src/configparser.cpp
@@ -37,6 +37,17 @@
# include <unistd.h>
#endif
+namespace
+{
+ std::string GetPrintable(int chr)
+ {
+ if (isprint(chr))
+ return INSP_FORMAT("{} (0x{:x})", (char)chr, chr);
+ else
+ return INSP_FORMAT("0x{:x}", chr);
+ }
+}
+
enum ParseFlags
{
// Executable includes are disabled.
@@ -158,14 +169,14 @@ struct Parser final
}
else if (ch != '=')
{
- throw CoreException("Invalid character " + std::string(1, ch) + " in key (" + key + ")");
+ throw CoreException("Invalid character in key " + key + ": " + GetPrintable(ch));
}
std::string value;
ch = next();
if (ch != '"')
{
- throw CoreException("Invalid character in value of <" + tag->name + ":" + key + ">");
+ throw CoreException("Invalid character in value of <" + tag->name + ":" + key + ">: " + GetPrintable(ch));
}
while (true)
{
@@ -244,7 +255,9 @@ struct Parser final
if (spc == '>')
unget(spc);
else if (!isspace(spc))
- throw CoreException("Invalid character in tag name");
+ {
+ throw CoreException("Invalid character in tag name: " + GetPrintable(spc));
+ }
if (name.empty())
throw CoreException("Empty tag name");