Skip to content

Commit

Permalink
Format eacces errors in a more readable way
Browse files Browse the repository at this point in the history
Amended with small whitespace changes and removing an unused clause.
  • Loading branch information
michaelklishin authored and essen committed Jan 31, 2017
1 parent f4f297c commit 066a714
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/ranch.erl
Expand Up @@ -85,6 +85,7 @@ maybe_started(Res) ->
Res.

start_error(E=eaddrinuse, _) -> {error, E};
start_error(E=eacces, _) -> {error, E};
start_error(E=no_cert, _) -> {error, E};
start_error(_, Error) -> Error.

Expand Down
28 changes: 23 additions & 5 deletions test/acceptor_SUITE.erl
Expand Up @@ -36,7 +36,8 @@ groups() ->
tcp_set_max_connections,
tcp_set_max_connections_clean,
tcp_upgrade,
tcp_error_eaddrinuse
tcp_error_eaddrinuse,
tcp_error_eacces
]}, {ssl, [
ssl_accept_error,
ssl_accept_socket,
Expand All @@ -45,7 +46,8 @@ groups() ->
ssl_sni_echo,
ssl_sni_fail,
ssl_error_eaddrinuse,
ssl_error_no_cert
ssl_error_no_cert,
ssl_error_eacces
]}, {misc, [
misc_bad_transport,
misc_bad_transport_options,
Expand Down Expand Up @@ -258,7 +260,7 @@ do_ssl_sni_fail() ->
ok.

ssl_error_eaddrinuse(_) ->
doc("Check that eaddrinuse returns a simplified error."),
doc("Ensure that failure due to an eaddrinuse returns a compact readable error."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
{ok, _} = ranch:start_listener(Name, 1, ranch_ssl, Opts, active_echo_protocol, []),
Expand All @@ -271,10 +273,18 @@ ssl_error_eaddrinuse(_) ->
ok.

ssl_error_no_cert(_) ->
doc("Check that missing certificate returns a simplified error."),
doc("Ensure that failure due to missing certificate returns a compact readable error."),
{error, no_cert} = ranch:start_listener(name(), 1, ranch_ssl, [], active_echo_protocol, []),
ok.

ssl_error_eacces(_) ->
doc("Ensure that failure due to an eacces returns a compact readable error."),
Name = name(),
Opts = ct_helper:get_certs_from_ets(),
{error, eacces} = ranch:start_listener(Name, 1,
ranch_ssl, [{port, 283}|Opts], active_echo_protocol, []),
ok.

%% tcp.

tcp_accept_socket(_) ->
Expand Down Expand Up @@ -461,7 +471,7 @@ tcp_upgrade(_) ->
ok = ranch:stop_listener(Name).

tcp_error_eaddrinuse(_) ->
doc("Check that eaddrinuse returns a simplified error."),
doc("Ensure that failure due to an eaddrinuse returns a compact readable error."),
Name = name(),
{ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], active_echo_protocol, []),
Port = ranch:get_port(Name),
Expand All @@ -472,6 +482,14 @@ tcp_error_eaddrinuse(_) ->
{'EXIT', _} = begin catch ranch:get_port(Name) end,
ok.

tcp_error_eacces(_) ->
doc("Ensure that failure due to an eacces returns a compact readable error."),
Name = name(),
{error, eacces} = ranch:start_listener(Name, 1,
ranch_tcp, [{port, 283}], active_echo_protocol, []),
ok.


%% Supervisor tests

connection_type_supervisor(_) ->
Expand Down

0 comments on commit 066a714

Please sign in to comment.