commit - 33be863885ab69ec32799c7d6844609fa6a5e039
commit + 2f4289de81ec2f59955947bad61a6e9037183b63
blob - 84d7f97f0e3b15bfa61f8da4c5e2419468355860
blob + f5aedf985eac8c5fc2e226eb082d9746ecff4e70
--- vostok/error.h
+++ vostok/error.h
explicit Print(int error=errno) : m_error{error} {}
void operator() () const
{
- g_log << "Error code: " << std::dec << m_error << ". " << strerror(m_error) << std::endl;
+ g_log << "Error code (" << std::dec << m_error << "): " << strerror(m_error);
}
private:
)
{
print_action();
- g_log << " failed." << std::endl;
+ g_log << " failed. ";
print_error();
+ g_log << std::endl;
}
template<typename TPrintError>
blob - 3febc5c0529b541c35b077e06a481ff91dc8033a
blob + 88f9a8d0e00e67af58036b1876e9f289344e7fcd
--- vostok/transport.cc
+++ vostok/transport.cc
};
+class PrintIfError
+{
+public:
+ explicit PrintIfError(czstring error) : m_error{error} {}
+ void operator() () const
+ {
+ if (m_error)
+ error::g_log << "Error: " << m_error;
+ }
+
+private:
+ czstring m_error;
+};
+
+
bool read(NotNull<struct tls *> ctx, std::vector<char> &buff)
{
ssize_t ret{};
}
if (ret == -1)
{
- const auto last_error = tls_error(ctx);
- error::occurred(
- "TLS read",
- [last_error]
- {
- if (last_error)
- error::g_log << "Error: " << last_error << std::endl;
- }
- );
+ error::occurred("TLS read", PrintIfError{tls_error(ctx)});
return false;
}
buff.resize(ret);
if (tls_configure(ctx.get(), cfg.get()) == -1)
{
- auto config_error = tls_config_error(cfg.get());
- error::occurred(
- "Configure TLS context",
- [config_error]
- {
- if (config_error)
- error::g_log << "Error: " << config_error << std::endl;
- }
- );
+ error::occurred("Configure TLS context", PrintIfError{tls_config_error(cfg.get())});
return;
}
}
if (ret == -1)
{
- const auto last_error = tls_error(ctx);
- error::occurred(
- "TLS write",
- [last_error]
- {
- if (last_error)
- error::g_log << "Error: " << last_error << std::endl;
- }
- );
+ error::occurred("TLS write", PrintIfError{tls_error(ctx)});
return false;
}
return true;
blob - 1522a58db3d9e2729758ad19dda6d5cf73e2ba8f
blob + c1151107c5b33b391e6681df5f6523245e2d71ed
--- vostok/vostok.cc
+++ vostok/vostok.cc
switch (parse_result)
{
case url_too_short:
- error::occurred("parse URL", []{error::g_log << meta::sz_url_too_short << "." << std::endl;});
+ error::occurred("parse URL", []{error::g_log << meta::sz_url_too_short;});
transport::send_response(accepted_client->get_ctx(), gemini::STATUS_59_BAD_REQUEST, meta::url_too_short);
return;
case url_non_gemini:
- error::occurred("parse URL", []{error::g_log << meta::sz_non_gemini << "." << std::endl;});
+ error::occurred("parse URL", []{error::g_log << meta::sz_non_gemini;});
transport::send_response(accepted_client->get_ctx(), gemini::STATUS_53_PROXY_REQUEST_REFUSED, meta::non_gemini);
return;
case url_root_traverse:
- error::occurred("parse URL", []{error::g_log << meta::sz_root_traverse << "." << std::endl;});
+ error::occurred("parse URL", []{error::g_log << meta::sz_root_traverse;});
transport::send_response(accepted_client->get_ctx(), gemini::STATUS_50_PERMANENT_FAILURE, meta::root_traverse);
return;
[&e]
{
error::g_log << "Error: " << std::dec << e.code()
- << ". " << e.what() << std::endl;
+ << ". " << e.what();
}
);
}