From a95ab5a7ce97cda84fb0b8dfaca8bda7b0f1b314 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 1 Feb 2025 18:10:42 +0000 Subject: [PATCH] Add better debugging for text conversion failure --- lib/texts/TextOperations.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/texts/TextOperations.cpp b/lib/texts/TextOperations.cpp index 8410867d0..d29dbefdf 100644 --- a/lib/texts/TextOperations.cpp +++ b/lib/texts/TextOperations.cpp @@ -161,12 +161,24 @@ uint32_t TextOperations::getUnicodeCodepoint(char data, const std::string & enco std::string TextOperations::toUnicode(const std::string &text, const std::string &encoding) { - return boost::locale::conv::to_utf(text, encoding); + try { + return boost::locale::conv::to_utf(text, encoding); + } + catch (const boost::locale::conv::conversion_error &) + { + throw std::runtime_error("Failed to convert text '" + text + "' from encoding " + encoding ); + } } std::string TextOperations::fromUnicode(const std::string &text, const std::string &encoding) { - return boost::locale::conv::from_utf(text, encoding); + try { + return boost::locale::conv::from_utf(text, encoding); + } + catch (const boost::locale::conv::conversion_error &) + { + throw std::runtime_error("Failed to convert text '" + text + "' to encoding " + encoding ); + } } void TextOperations::trimRightUnicode(std::string & text, const size_t amount)