Skip to content

Commit e9f25dd

Browse files
committed
Avoid ugly exception in log on unknown inv type
It is unexpected behavior for `ToString` to raise an exception. It is expected to do a best-effort attempt at formatting but never fail. Catch the exception and simply print unknown inv types as hexadecimal. Fixes #9110.
1 parent e984730 commit e9f25dd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/protocol.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ std::string CInv::GetCommand() const
181181

182182
std::string CInv::ToString() const
183183
{
184-
return strprintf("%s %s", GetCommand(), hash.ToString());
184+
try {
185+
return strprintf("%s %s", GetCommand(), hash.ToString());
186+
} catch(const std::out_of_range &) {
187+
return strprintf("0x%08x %s", type, hash.ToString());
188+
}
185189
}
186190

187191
const std::vector<std::string> &getAllNetMessageTypes()

0 commit comments

Comments
 (0)