Skip to content

Commit a040881

Browse files
authored
server_split now handles exception when deserializing (#81)
1 parent bac02bc commit a040881

File tree

4 files changed

+19
-36
lines changed

4 files changed

+19
-36
lines changed

src/server/xcontrol.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,7 @@ namespace xeus
6262
zmq::multipart_t wire_msg;
6363
if (wire_msg.recv(m_control, flags))
6464
{
65-
try
66-
{
67-
return p_server->deserialize(wire_msg);
68-
}
69-
catch (std::exception& e)
70-
{
71-
std::cerr << e.what() << std::endl;
72-
}
65+
return p_server->deserialize(wire_msg);
7366
}
7467
return std::nullopt;
7568
}

src/server/xserver_zmq_split_impl.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* The full license is in the file LICENSE, distributed with this software. *
88
****************************************************************************/
99

10+
#include <iostream>
11+
1012
#include "xserver_zmq_split_impl.hpp"
1113
#include "../common/xzmq_serializer.hpp"
1214

@@ -134,9 +136,17 @@ namespace xeus
134136
config.m_hb_port = m_heartbeat.get_port();
135137
}
136138

137-
xmessage xserver_zmq_split_impl::deserialize(zmq::multipart_t& wire_msg) const
139+
std::optional<xmessage> xserver_zmq_split_impl::deserialize(zmq::multipart_t& wire_msg) const
138140
{
139-
return xzmq_serializer::deserialize(wire_msg, *p_auth);
141+
try
142+
{
143+
return xzmq_serializer::deserialize(wire_msg, *p_auth);
144+
}
145+
catch (std::exception& e)
146+
{
147+
std::cerr << e.what() << std::endl;
148+
}
149+
return std::nullopt;
140150
}
141151

142152
zmq::multipart_t xserver_zmq_split_impl::serialize_iopub(xpub_message&& msg)

src/server/xserver_zmq_split_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace xeus
6363
void abort_queue(const listener& l, long polling_interval);
6464
void update_config(xconfiguration& config) const;
6565

66-
xmessage deserialize(zmq::multipart_t& wire_msg) const;
66+
std::optional<xmessage> deserialize(zmq::multipart_t& wire_msg) const;
6767
zmq::multipart_t serialize_iopub(xpub_message&& msg);
6868

6969
private:

src/server/xshell.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <thread>
1111
#include <chrono>
12-
#include <iostream>
1312

1413
#include "xserver_zmq_split_impl.hpp"
1514
#include "xshell.hpp"
@@ -86,14 +85,7 @@ namespace xeus
8685
zmq::multipart_t wire_msg;
8786
if (wire_msg.recv(m_shell, flags))
8887
{
89-
try
90-
{
91-
return p_server->deserialize(wire_msg);
92-
}
93-
catch(std::exception& e)
94-
{
95-
std::cerr << e.what() << std::endl;
96-
}
88+
return p_server->deserialize(wire_msg);
9789
}
9890
return std::nullopt;
9991
}
@@ -118,15 +110,7 @@ namespace xeus
118110
message.send(m_stdin);
119111
zmq::multipart_t wire_msg;
120112
wire_msg.recv(m_stdin);
121-
try
122-
{
123-
return p_server->deserialize(wire_msg);
124-
}
125-
catch (std::exception& e)
126-
{
127-
std::cerr << e.what() << std::endl;
128-
}
129-
return std::nullopt;
113+
return p_server->deserialize(wire_msg);
130114
}
131115

132116
void xshell::send_controller(std::string message)
@@ -151,14 +135,10 @@ namespace xeus
151135
return;
152136
}
153137

154-
try
155-
{
156-
xmessage msg = p_server->deserialize(wire_msg);
157-
l(std::move(msg));
158-
}
159-
catch (std::exception& e)
138+
auto msg = p_server->deserialize(wire_msg);
139+
if (msg)
160140
{
161-
std::cerr << e.what() << std::endl;
141+
l(std::move(msg.value()));
162142
}
163143
std::this_thread::sleep_for(std::chrono::milliseconds(polling_interval));
164144
}

0 commit comments

Comments
 (0)