Commit 59d42ce0 authored by Dominik Charousset's avatar Dominik Charousset

Clean up remaining calls to render()

parent 896e421b
...@@ -30,8 +30,7 @@ using kickoff_atom = atom_constant<atom("kickoff")>; ...@@ -30,8 +30,7 @@ using kickoff_atom = atom_constant<atom("kickoff")>;
// utility function to print an exit message with custom name // utility function to print an exit message with custom name
void print_on_exit(scheduled_actor* self, const std::string& name) { void print_on_exit(scheduled_actor* self, const std::string& name) {
self->attach_functor([=](const error& reason) { self->attach_functor([=](const error& reason) {
aout(self) << name << " exited: " << self->home_system().render(reason) aout(self) << name << " exited: " << to_string(reason) << endl;
<< endl;
}); });
} }
...@@ -174,8 +173,8 @@ void run_server(actor_system& system, const config& cfg) { ...@@ -174,8 +173,8 @@ void run_server(actor_system& system, const config& cfg) {
auto server_actor = system.middleman().spawn_server(server, cfg.port, auto server_actor = system.middleman().spawn_server(server, cfg.port,
pong_actor); pong_actor);
if (!server_actor) if (!server_actor)
cerr << "unable to spawn server: " cerr << "unable to spawn server: " << to_string(server_actor.error())
<< system.render(server_actor.error()) << endl; << endl;
} }
void run_client(actor_system& system, const config& cfg) { void run_client(actor_system& system, const config& cfg) {
...@@ -184,8 +183,8 @@ void run_client(actor_system& system, const config& cfg) { ...@@ -184,8 +183,8 @@ void run_client(actor_system& system, const config& cfg) {
auto io_actor = system.middleman().spawn_client(protobuf_io, cfg.host, auto io_actor = system.middleman().spawn_client(protobuf_io, cfg.host,
cfg.port, ping_actor); cfg.port, ping_actor);
if (!io_actor) { if (!io_actor) {
cout << "cannot connect to " << cfg.host << " at port " << cfg.port cout << "cannot connect to " << cfg.host << " at port " << cfg.port << ": "
<< ": " << system.render(io_actor.error()) << endl; << to_string(io_actor.error()) << endl;
return; return;
} }
send_as(*io_actor, ping_actor, kickoff_atom::value, *io_actor); send_as(*io_actor, ping_actor, kickoff_atom::value, *io_actor);
......
...@@ -192,8 +192,8 @@ void run_server(actor_system& system, const config& cfg) { ...@@ -192,8 +192,8 @@ void run_server(actor_system& system, const config& cfg) {
auto server_actor = system.middleman().spawn_server(server, cfg.port, auto server_actor = system.middleman().spawn_server(server, cfg.port,
pong_actor); pong_actor);
if (!server_actor) { if (!server_actor) {
std::cerr << "failed to spawn server: " std::cerr << "failed to spawn server: " << to_string(server_actor.error())
<< system.render(server_actor.error()) << endl; << endl;
return; return;
} }
print_on_exit(*server_actor, "server"); print_on_exit(*server_actor, "server");
...@@ -205,7 +205,7 @@ void run_client(actor_system& system, const config& cfg) { ...@@ -205,7 +205,7 @@ void run_client(actor_system& system, const config& cfg) {
auto io_actor = system.middleman().spawn_client(broker_impl, cfg.host, auto io_actor = system.middleman().spawn_client(broker_impl, cfg.host,
cfg.port, ping_actor); cfg.port, ping_actor);
if (!io_actor) { if (!io_actor) {
std::cerr << "failed to spawn client: " << system.render(io_actor.error()) std::cerr << "failed to spawn client: " << to_string(io_actor.error())
<< endl; << endl;
return; return;
} }
......
...@@ -77,8 +77,8 @@ public: ...@@ -77,8 +77,8 @@ public:
void caf_main(actor_system& system, const config& cfg) { void caf_main(actor_system& system, const config& cfg) {
auto server_actor = system.middleman().spawn_server(server, cfg.port); auto server_actor = system.middleman().spawn_server(server, cfg.port);
if (!server_actor) { if (!server_actor) {
cerr << "*** cannot spawn server: " cerr << "*** cannot spawn server: " << to_string(server_actor.error())
<< system.render(server_actor.error()) << endl; << endl;
return; return;
} }
cout << "*** listening on port " << cfg.port << endl; cout << "*** listening on port " << cfg.port << endl;
......
...@@ -37,7 +37,7 @@ void caf_main(actor_system& system) { ...@@ -37,7 +37,7 @@ void caf_main(actor_system& system) {
: "server\n"); : "server\n");
}, },
[&](error& err) { [&](error& err) {
aout(self) << "received error " << system.render(err) << " from " aout(self) << "received error " << to_string(err) << " from "
<< (self->current_sender() == worker ? "worker\n" << (self->current_sender() == worker ? "worker\n"
: "server\n"); : "server\n");
}); });
......
...@@ -101,8 +101,7 @@ template <class Handle, class... Ts> ...@@ -101,8 +101,7 @@ template <class Handle, class... Ts>
void tester(scoped_actor& self, const Handle& hdl, int32_t x, int32_t y, void tester(scoped_actor& self, const Handle& hdl, int32_t x, int32_t y,
Ts&&... xs) { Ts&&... xs) {
auto handle_err = [&](const error& err) { auto handle_err = [&](const error& err) {
aout(self) << "AUT (actor under test) failed: " aout(self) << "AUT (actor under test) failed: " << to_string(err) << endl;
<< self->system().render(err) << endl;
}; };
// first test: x + y = z // first test: x + y = z
self->request(hdl, infinite, add_atom_v, x, y) self->request(hdl, infinite, add_atom_v, x, y)
......
...@@ -72,7 +72,7 @@ void caf_main(actor_system& system, const config&) { ...@@ -72,7 +72,7 @@ void caf_main(actor_system& system, const config&) {
[&](double z) { aout(self) << x << " / " << y << " = " << z << endl; }, [&](double z) { aout(self) << x << " / " << y << " = " << z << endl; },
[&](const error& err) { [&](const error& err) {
aout(self) << "*** cannot compute " << x << " / " << y << " => " aout(self) << "*** cannot compute " << x << " / " << y << " => "
<< system.render(err) << endl; << to_string(err) << endl;
}); });
} }
......
...@@ -56,8 +56,7 @@ void blocking_testee(blocking_actor* self, vector<cell> cells) { ...@@ -56,8 +56,7 @@ void blocking_testee(blocking_actor* self, vector<cell> cells) {
aout(self) << "cell #" << x.id() << " -> " << y << endl; aout(self) << "cell #" << x.id() << " -> " << y << endl;
}, },
[&](error& err) { [&](error& err) {
aout(self) << "cell #" << x.id() << " -> " aout(self) << "cell #" << x.id() << " -> " << to_string(err) << endl;
<< self->system().render(err) << endl;
}); });
} }
......
...@@ -54,8 +54,8 @@ void tester(event_based_actor* self, const calculator_type& testee) { ...@@ -54,8 +54,8 @@ void tester(event_based_actor* self, const calculator_type& testee) {
}); });
}, },
[=](const error& err) { [=](const error& err) {
aout(self) << "AUT (actor under test) failed: " aout(self) << "AUT (actor under test) failed: " << to_string(err)
<< self->system().render(err) << endl; << endl;
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}); });
} }
......
...@@ -79,7 +79,7 @@ void ChatWidget::sendChatMessage() { ...@@ -79,7 +79,7 @@ void ChatWidget::sendChatMessage() {
auto x = system().groups().get(mod, g); auto x = system().groups().get(mod, g);
if (! x) if (! x)
print("*** error: " print("*** error: "
+ QString::fromUtf8(system().render(x.error()).c_str())); + QString::fromUtf8(to_string(x.error()).c_str()));
else else
self()->send(self(), atom("join"), std::move(*x)); self()->send(self(), atom("join"), std::move(*x));
}, },
...@@ -128,7 +128,7 @@ void ChatWidget::joinGroup() { ...@@ -128,7 +128,7 @@ void ChatWidget::joinGroup() {
string gid = gname.midRef(pos+1).toUtf8().constData(); string gid = gname.midRef(pos+1).toUtf8().constData();
auto x = system().groups().get(mod, gid); auto x = system().groups().get(mod, gid);
if (! x) if (! x)
QMessageBox::critical(this, "Error", system().render(x.error()).c_str()); QMessageBox::critical(this, "Error", to_string(x.error()).c_str());
else else
self()->send(self(), join_atom::value, std::move(*x)); self()->send(self(), join_atom::value, std::move(*x));
} }
......
...@@ -59,9 +59,8 @@ int main(int argc, char** argv) { ...@@ -59,9 +59,8 @@ int main(int argc, char** argv) {
auto group_uri = cfg.group_id.substr(p + 1); auto group_uri = cfg.group_id.substr(p + 1);
auto g = system.groups().get(module, group_uri); auto g = system.groups().get(module, group_uri);
if (! g) { if (! g) {
cerr << "*** unable to get group " << group_uri cerr << "*** unable to get group " << group_uri << " from module "
<< " from module " << module << ": " << module << ": " << to_string(g.error()) << endl;
<< system.render(g.error()) << endl;
return -1; return -1;
} }
grp = std::move(*g); grp = std::move(*g);
......
...@@ -145,7 +145,7 @@ void connecting(stateful_actor<state>* self, const std::string& host, ...@@ -145,7 +145,7 @@ void connecting(stateful_actor<state>* self, const std::string& host,
}, },
[=](const error& err) { [=](const error& err) {
aout(self) << R"(*** cannot connect to ")" << host << R"(":)" << port aout(self) << R"(*** cannot connect to ")" << host << R"(":)" << port
<< " => " << self->system().render(err) << endl; << " => " << to_string(err) << endl;
self->become(unconnected(self)); self->become(unconnected(self));
}); });
} }
...@@ -286,7 +286,7 @@ void run_server(actor_system& system, const config& cfg) { ...@@ -286,7 +286,7 @@ void run_server(actor_system& system, const config& cfg) {
cout << "*** try publish at port " << cfg.port << endl; cout << "*** try publish at port " << cfg.port << endl;
auto expected_port = io::publish(calc, cfg.port); auto expected_port = io::publish(calc, cfg.port);
if (!expected_port) { if (!expected_port) {
std::cerr << "*** publish failed: " << system.render(expected_port.error()) std::cerr << "*** publish failed: " << to_string(expected_port.error())
<< endl; << endl;
return; return;
} }
......
...@@ -85,7 +85,7 @@ void run_server(actor_system& system, const config& cfg) { ...@@ -85,7 +85,7 @@ void run_server(actor_system& system, const config& cfg) {
auto res = system.middleman().publish_local_groups(cfg.port); auto res = system.middleman().publish_local_groups(cfg.port);
if (!res) { if (!res) {
std::cerr << "*** publishing local groups failed: " std::cerr << "*** publishing local groups failed: "
<< system.render(res.error()) << std::endl; << to_string(res.error()) << std::endl;
return; return;
} }
std::cout << "*** listening at port " << *res << std::endl std::cout << "*** listening at port " << *res << std::endl
...@@ -112,7 +112,7 @@ void run_client(actor_system& system, const config& cfg) { ...@@ -112,7 +112,7 @@ void run_client(actor_system& system, const config& cfg) {
anon_send(client_actor, join_atom_v, std::move(*tmp)); anon_send(client_actor, join_atom_v, std::move(*tmp));
else else
std::cerr << R"(*** failed to parse ")" << uri << R"(" as group URI: )" std::cerr << R"(*** failed to parse ")" << uri << R"(" as group URI: )"
<< system.render(tmp.error()) << std::endl; << to_string(tmp.error()) << std::endl;
} }
std::istream_iterator<line> eof; std::istream_iterator<line> eof;
std::vector<std::string> words; std::vector<std::string> words;
......
...@@ -115,7 +115,7 @@ struct config : actor_system_config { ...@@ -115,7 +115,7 @@ struct config : actor_system_config {
void server(actor_system& system, const config& cfg) { void server(actor_system& system, const config& cfg) {
auto res = system.middleman().open(cfg.port); auto res = system.middleman().open(cfg.port);
if (!res) { if (!res) {
cerr << "*** cannot open port: " << system.render(res.error()) << endl; cerr << "*** cannot open port: " << to_string(res.error()) << endl;
return; return;
} }
cout << "*** running on port: " << *res << endl cout << "*** running on port: " << *res << endl
...@@ -127,7 +127,7 @@ void server(actor_system& system, const config& cfg) { ...@@ -127,7 +127,7 @@ void server(actor_system& system, const config& cfg) {
void client(actor_system& system, const config& cfg) { void client(actor_system& system, const config& cfg) {
auto node = system.middleman().connect(cfg.host, cfg.port); auto node = system.middleman().connect(cfg.host, cfg.port);
if (!node) { if (!node) {
cerr << "*** connect failed: " << system.render(node.error()) << endl; cerr << "*** connect failed: " << to_string(node.error()) << endl;
return; return;
} }
auto type = "calculator"; // type of the actor we wish to spawn auto type = "calculator"; // type of the actor we wish to spawn
...@@ -136,8 +136,7 @@ void client(actor_system& system, const config& cfg) { ...@@ -136,8 +136,7 @@ void client(actor_system& system, const config& cfg) {
auto worker = system.middleman().remote_spawn<calculator>(*node, type, args, auto worker = system.middleman().remote_spawn<calculator>(*node, type, args,
tout); tout);
if (!worker) { if (!worker) {
cerr << "*** remote spawn failed: " << system.render(worker.error()) cerr << "*** remote spawn failed: " << to_string(worker.error()) << endl;
<< endl;
return; return;
} }
// start using worker in main loop // start using worker in main loop
......
...@@ -61,12 +61,10 @@ namespace caf { ...@@ -61,12 +61,10 @@ namespace caf {
/// ///
/// # Why is there no `string()` member function? /// # Why is there no `string()` member function?
/// ///
/// The C++ standard library uses category singletons and virtual dispatching /// The C++ standard library uses category singletons and virtual dispatching to
/// to correlate error codes to descriptive strings. However, singletons are /// correlate error codes to descriptive strings. However, singletons are a poor
/// a poor choice when it comes to serialization. CAF uses atoms for /// choice when it comes to serialization. CAF uses type IDs and meta objects
/// categories instead and requires users to register custom error categories /// instead.
/// to the actor system. This makes the actor system the natural instance for
/// rendering error messages via `actor_system::render(const error&)`.
class CAF_CORE_EXPORT error : detail::comparable<error> { class CAF_CORE_EXPORT error : detail::comparable<error> {
public: public:
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
......
...@@ -71,8 +71,6 @@ CAF_TEST(test_serial_reply) { ...@@ -71,8 +71,6 @@ CAF_TEST(test_serial_reply) {
CAF_MESSAGE("ID of main: " << self->id()); CAF_MESSAGE("ID of main: " << self->id());
self->request(master, infinite, hi_atom::value) self->request(master, infinite, hi_atom::value)
.receive([](ho_atom) { CAF_MESSAGE("received 'ho'"); }, .receive([](ho_atom) { CAF_MESSAGE("received 'ho'"); },
[&](const error& err) { [&](const error& err) { CAF_ERROR("Error: " << to_string(err)); });
CAF_ERROR("Error: " << self->system().render(err));
});
CAF_REQUIRE(self->mailbox().empty()); CAF_REQUIRE(self->mailbox().empty());
} }
...@@ -646,9 +646,7 @@ struct test_coordinator_fixture_fetch_helper { ...@@ -646,9 +646,7 @@ struct test_coordinator_fixture_fetch_helper {
operator()(caf::response_handle<Self, Policy<Interface>>& from) const { operator()(caf::response_handle<Self, Policy<Interface>>& from) const {
std::tuple<Ts...> result; std::tuple<Ts...> result;
from.receive([&](Ts&... xs) { result = std::make_tuple(std::move(xs)...); }, from.receive([&](Ts&... xs) { result = std::make_tuple(std::move(xs)...); },
[&](caf::error& err) { [&](caf::error& err) { CAF_FAIL(err); });
FAIL(from.self()->system().render(err));
});
return result; return result;
} }
}; };
...@@ -659,9 +657,7 @@ struct test_coordinator_fixture_fetch_helper<T> { ...@@ -659,9 +657,7 @@ struct test_coordinator_fixture_fetch_helper<T> {
T operator()(caf::response_handle<Self, Policy<Interface>>& from) const { T operator()(caf::response_handle<Self, Policy<Interface>>& from) const {
T result; T result;
from.receive([&](T& x) { result = std::move(x); }, from.receive([&](T& x) { result = std::move(x); },
[&](caf::error& err) { [&](caf::error& err) { CAF_FAIL(err); });
FAIL(from.self()->system().render(err));
});
return result; return result;
} }
}; };
......
...@@ -274,8 +274,8 @@ construction arguments passed as message can mismatch, this version of ...@@ -274,8 +274,8 @@ construction arguments passed as message can mismatch, this version of
auto x = system.spawn<calculator>("calculator", make_message()); auto x = system.spawn<calculator>("calculator", make_message());
if (! x) { if (! x) {
std::cerr << "*** unable to spawn calculator: " std::cerr << "*** unable to spawn calculator: " << to_string(x.error())
<< system.render(x.error()) << std::endl; << std::endl;
return; return;
} }
calculator c = std::move(*x); calculator c = std::move(*x);
......
...@@ -14,8 +14,8 @@ name, joining, and leaving. ...@@ -14,8 +14,8 @@ name, joining, and leaving.
std::string id = "foo"; std::string id = "foo";
auto expected_grp = system.groups().get(module, id); auto expected_grp = system.groups().get(module, id);
if (! expected_grp) { if (! expected_grp) {
std::cerr << "*** cannot load group: " std::cerr << "*** cannot load group: " << to_string(expected_grp.error())
<< system.render(expected_grp.error()) << std::endl; << std::endl;
return; return;
} }
auto grp = std::move(*expected_grp); auto grp = std::move(*expected_grp);
......
...@@ -92,12 +92,10 @@ connect to the published actor by calling ``remote_actor``: ...@@ -92,12 +92,10 @@ connect to the published actor by calling ``remote_actor``:
// node B // node B
auto ping = system.middleman().remote_actor("node A", 4242); auto ping = system.middleman().remote_actor("node A", 4242);
if (! ping) { if (!ping)
cerr << "unable to connect to node A: " cerr << "unable to connect to node A: " << to_string(ping.error()) << '\n';
<< system.render(ping.error()) << std::endl; else
} else {
self->send(*ping, ping_atom::value); self->send(*ping, ping_atom::value);
}
There is no difference between server and client after the connection phase. There is no difference between server and client after the connection phase.
Remote actors use the same handle types as local actors and are thus fully Remote actors use the same handle types as local actors and are thus fully
......
...@@ -161,8 +161,8 @@ void bootstrap(actor_system& system, const string& wdir, ...@@ -161,8 +161,8 @@ void bootstrap(actor_system& system, const string& wdir,
// possible addresses slaves can use to connect to us // possible addresses slaves can use to connect to us
auto port_res = system.middleman().publish(self, 0); auto port_res = system.middleman().publish(self, 0);
if (!port_res) { if (!port_res) {
cerr << "fatal: unable to publish actor: " cerr << "fatal: unable to publish actor: " << to_string(port_res.error())
<< system.render(port_res.error()) << endl; << endl;
return; return;
} }
auto port = *port_res; auto port = *port_res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment