reactphp / socket

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

Improve error messages for failed connections to include errno #271

Closed clue closed 3 years ago

clue commented 3 years ago

This changeset improves error messages for failed connections to include the errno (the internal error number exposed by the underlying system functions and its constant name).

- Connection to tcp://localhost:80 cancelled during DNS lookup
- 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
+ Connection to tcp://localhost:80 cancelled during DNS lookup (ECONNABORTED)
+ Connection to tcp://localhost:80 failed: Last error for IPv4: Connection to tcp://127.0.0.1:80 failed: Connection refused (ECONNREFUSED). Previous error for IPv6: Connection to tcp://[::1]:80 failed: Connection refused (ECONNREFUSED)

The errno value describes the type of error that has been encountered. This value is exposed by a number of system functions but not always exposed by many higher-level PHP functions. This changeset implements a number of ways to report or look up the errno value based on the errstr and find a matching errno constant name. This can be useful to provide more context and more descriptive error messages. The specific error conditions and codes used are system specific and in many cases are only exposed when ext-sockets is available (which is entirely optional, but the default on most installations of PHP).

Builds on top of #270, #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