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