Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional callback ranch_transport:format_error/1 #354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

juhlig
Copy link
Contributor

@juhlig juhlig commented Nov 18, 2024

Fixes #346.

No docs yet, wanted to see what you think of the implementation first. Will add more comments inline.

@@ -106,9 +106,14 @@ hide_socket_opts([{password, _}|SocketOpts]) ->
hide_socket_opts([SocketOpt|SocketOpts]) ->
[SocketOpt|hide_socket_opts(SocketOpts)].

format_error(no_cert) ->
format_error(_, no_cert) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually belongs in ranch_ssl:format_error/1 (and is replicated there). For backwards compatibility with existing custom transports without an format_error implementation which may rely on ranch_acceptors_sup handling this, I left it in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write that in a comment.

true ->
Transport:format_error(Reason);
false ->
io_lib:format("~999999p", [Reason])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can do better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~0p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah... We should change that in other places as well then. In this PR, or a separate one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR is fine but a separate commit.

"no certificate provided; see cert, certfile, sni_fun or sni_hosts options";
format_error(reuseport_local) ->
format_error(_, reuseport_local) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generated by ranch_acceptors_sup itself as it is a misconfiguration specific to ranch. Therefore, I left it here, it doesn't seem to fit into a transport.

format_error(Reason) ->
inet:format_error(Reason).
format_error(Transport, Reason) ->
case erlang:function_exported(Transport, format_error, 1) of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment saying this will be required in 3.0, and for now let's consider/document it as optional.

@essen
Copy link
Member

essen commented Nov 18, 2024

Looks fine yes.

@essen
Copy link
Member

essen commented Nov 18, 2024

Maybe have a test for the custom transport if we don't already.

@juhlig
Copy link
Contributor Author

juhlig commented Nov 18, 2024

Maybe have a test for the custom transport if we don't already.

I think we don't. There is ranch_erlang_transport, but that is for concuerror stuff.

@juhlig
Copy link
Contributor Author

juhlig commented Nov 18, 2024

Wait, we have concuerror tests? 😳 Since when? That completely went by me 😅

@essen
Copy link
Member

essen commented Nov 18, 2024

Yes. #261

@essen
Copy link
Member

essen commented Nov 18, 2024

@juhlig juhlig force-pushed the ranch_transport_format_error branch from 5de33d5 to 90da425 Compare November 21, 2024 09:51
@juhlig
Copy link
Contributor Author

juhlig commented Nov 21, 2024

@essen added docs and a test and changed ~999999p to ~0p in a separate commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minor: ranch_ssl:listen can return non-atom error reasons
2 participants