reactphp / socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP.
https://reactphp.org/socket/
MIT License
1.21k stars 157 forks source link

Improve error messages for failed connections #270

Closed clue closed 3 years ago

clue commented 3 years ago

This changeset improves error messages for failed connections. In particular, failed TCP/IP connections using the happy eyeballs connector (the default) or the old DNS connector will now report the hostname once at the beginning of the message and will not show its internal hostname parameter multiple times:

- Connection to tcp://localhost:80 failed: Last error for IPv4: Connection to tcp://127.0.0.1:80?hostname=localhost failed: Connection refused. Previous error for IPv6: Connection to tcp://[::1]:80?hostname=localhost failed: Connection refused
+ Connection to tcp://localhost:80 failed: Last error for IPv4: Connection to tcp://127.0.0.1:80 failed: Connection refused. Previous error for IPv6: Connection to tcp://[::1]:80 failed: Connection refused

Likewise, we now make sure to always consistently include the URI scheme used in the error message. For instance, failed TLS connections will now include the appropriate URI scheme for the start of the message and show the underlying URI scheme for underlying TCP/IP connection issues such as this:

- Connection to localhost:443 failed: Last error for IPv4: Connection to tcp://127.0.0.1:443?hostname=localhost failed: Connection refused. Previous error for IPv6: Connection to tcp://[::1]:443?hostname=localhost failed: Connection refused
+ Connection to tls://localhost:443 failed: Last error for IPv4: Connection to tcp://127.0.0.1:443 failed: Connection refused. Previous error for IPv6: Connection to tcp://[::1]:443 failed: Connection refused

Builds on top of #265, #266, #267 and others such as https://github.com/clue/reactphp-redis/pull/116, https://github.com/friends-of-reactphp/mysql/pull/141 and more

clue commented 3 years ago

Updated to fix the build error on PHP < 7.4 by cleaning up any garbage memory references as also done in https://github.com/reactphp/dns/pull/118 and https://github.com/reactphp/dns/pull/160.

This is now ready for review :shipit: