diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index 2fdf9d290..3c55b2da7 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -258,7 +258,7 @@ namespace hex::prv { */ bool m_skipLoadInterface = false; - std::string m_errorMessage; + std::string m_errorMessage = "Unspecified error"; u64 m_pageSize = MaxPageSize; }; diff --git a/plugins/builtin/source/content/providers/intel_hex_provider.cpp b/plugins/builtin/source/content/providers/intel_hex_provider.cpp index 6f4d902d5..ce1e02100 100644 --- a/plugins/builtin/source/content/providers/intel_hex_provider.cpp +++ b/plugins/builtin/source/content/providers/intel_hex_provider.cpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace hex::plugin::builtin { @@ -26,7 +27,7 @@ namespace hex::plugin::builtin { throw std::runtime_error("Failed to parse hex digit"); } - std::map> parseIntelHex(const std::string &string) { + wolv::util::Expected>, std::string> parseIntelHex(const std::string &string) { std::map> result; u8 checksum = 0x00; @@ -148,8 +149,8 @@ namespace hex::plugin::builtin { offset++; } - } catch (const std::runtime_error &) { - return { }; + } catch (const std::runtime_error &e) { + return wolv::util::Unexpected(e.what()); } return result; @@ -193,12 +194,16 @@ namespace hex::plugin::builtin { bool IntelHexProvider::open() { auto file = wolv::io::File(m_sourceFilePath, wolv::io::File::Mode::Read); - if (!file.isValid()) + if (!file.isValid()) { + this->setErrorMessage(hex::format("hex.builtin.provider.file.error.open"_lang, m_sourceFilePath.string(), ::strerror(errno))); return false; + } auto data = intel_hex::parseIntelHex(file.readString()); - if (data.empty()) + if (!data.has_value()) { + this->setErrorMessage(data.error()); return false; + } u64 maxAddress = 0x00; for (auto &[address, bytes] : data) { diff --git a/plugins/builtin/source/content/providers/motorola_srec_provider.cpp b/plugins/builtin/source/content/providers/motorola_srec_provider.cpp index 746c63e9b..3c9598749 100644 --- a/plugins/builtin/source/content/providers/motorola_srec_provider.cpp +++ b/plugins/builtin/source/content/providers/motorola_srec_provider.cpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace hex::plugin::builtin { @@ -24,7 +25,7 @@ namespace hex::plugin::builtin { throw std::runtime_error("Failed to parse hex digit"); } - std::map> parseMotorolaSREC(const std::string &string) { + wolv::util::Expected>, std::string> parseMotorolaSREC(const std::string &string) { std::map> result; u64 offset = 0x00; @@ -161,8 +162,8 @@ namespace hex::plugin::builtin { while (std::isspace(string[offset]) && offset < string.length()) offset++; } - } catch (const std::runtime_error &) { - return { }; + } catch (const std::runtime_error &e) { + return wolv::util::Unexpected(e.what()); } return result; @@ -172,12 +173,16 @@ namespace hex::plugin::builtin { bool MotorolaSRECProvider::open() { auto file = wolv::io::File(m_sourceFilePath, wolv::io::File::Mode::Read); - if (!file.isValid()) + if (!file.isValid()) { + this->setErrorMessage(hex::format("hex.builtin.provider.file.error.open"_lang, m_sourceFilePath.string(), ::strerror(errno))); return false; + } auto data = motorola_srec::parseMotorolaSREC(file.readString()); - if (data.empty()) + if (!data.has_value()) { + this->setErrorMessage(data.error()); return false; + } u64 maxAddress = 0x00; for (auto &[address, bytes] : data) {