Skip to content

Commit

Permalink
fix: if IPC serialization exception happens, client app would crash c…
Browse files Browse the repository at this point in the history
…ause not exception handle provided.
  • Loading branch information
fxliang committed Jun 12, 2024
1 parent f16d356 commit 369834c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WeaselIPC/ContextUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ContextUpdater::_StoreCand(Deserializer::KeyType k,
std::wstringstream ss(value);
boost::archive::text_wiarchive ia(ss);

ia >> cinfo;
TryDeserialize(ia, cinfo);

for (auto& cand : cinfo.candies)
cand.str = unescape_string(cand.str);
Expand Down
10 changes: 10 additions & 0 deletions WeaselIPC/Deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

namespace weasel {

template <typename T>
void TryDeserialize(boost::archive::text_wiarchive& ia, T& t) {
try {
ia >> t;
} catch (const boost::archive::archive_exception& e) {
const std::string msg =
std::string("boost::archive::archive_exception: ") + e.what();
MessageBoxA(NULL, msg.c_str(), "IPC exception", MB_OK | MB_ICONERROR);
}
}
class Deserializer {
public:
typedef std::vector<std::wstring> KeyType;
Expand Down
2 changes: 1 addition & 1 deletion WeaselIPC/Styler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void Styler::Store(weasel::Deserializer::KeyType const& key,
std::wstringstream ss(value);
boost::archive::text_wiarchive ia(ss);

ia >> sty;
TryDeserialize(ia, sty);
}

weasel::Deserializer::Ptr Styler::Create(weasel::ResponseParser* pTarget) {
Expand Down

0 comments on commit 369834c

Please sign in to comment.