From f33ff7cbacb204adae9d53ad15829f44c4140525 Mon Sep 17 00:00:00 2001 From: Alexey Lebedeff Date: Fri, 22 Apr 2016 17:33:34 +0300 Subject: Improve error reporting Simplify some return values, improve error messages for eaddrinuse and no_cert. Amended to add tests and simpler code. Also hides the contents of cert and key transport options, if any. --- src/ranch_acceptors_sup.erl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/ranch_acceptors_sup.erl') diff --git a/src/ranch_acceptors_sup.erl b/src/ranch_acceptors_sup.erl index 67854d5..d716a33 100644 --- a/src/ranch_acceptors_sup.erl +++ b/src/ranch_acceptors_sup.erl @@ -49,8 +49,15 @@ init([Ref, NumAcceptors, Transport, TransOpts]) -> {ok, {{one_for_one, 1, 5}, Procs}}. -spec listen_error(any(), module(), any(), atom()) -> no_return(). -listen_error(Ref, Transport, TransOpts2, Reason) -> +listen_error(Ref, Transport, TransOpts0, Reason) -> + TransOpts1 = lists:keyreplace(cert, 1, TransOpts0, {cert, '...'}), + TransOpts = lists:keyreplace(key, 1, TransOpts1, {key, '...'}), error_logger:error_msg( - "Failed to start Ranch listener ~p in ~p:listen(~p) for reason ~p (~s)~n", - [Ref, Transport, TransOpts2, Reason, inet:format_error(Reason)]), + "Failed to start Ranch listener ~p in ~p:listen(~999999p) for reason ~p (~s)~n", + [Ref, Transport, TransOpts, Reason, format_error(Reason)]), exit({listen_error, Ref, Reason}). + +format_error(no_cert) -> + "no certificate provided; see cert, certfile, sni_fun or sni_hosts options"; +format_error(Reason) -> + inet:format_error(Reason). -- cgit v1.2.3