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

Propagate ConnectionException message via trigger_error() #57

Merged
merged 1 commit into from
Jan 15, 2022
Merged

Propagate ConnectionException message via trigger_error() #57

merged 1 commit into from
Jan 15, 2022

Conversation

filakhtov
Copy link
Contributor

What & Why?

As it presently stands, the ConnectionException is thrown when opening a socket fails and contains the system-level error code and message. This information, however, is only accessible if the throwConnectionExceptions flag is set and the original exception is propagated to the consumer. If the exception is disabled, then a user warning will be created using the trigger_error() function, which unfortunately does not carry an information from the exception, leading to inability to properly debug connection issues. With this change the original exception message will be appended to the produced warning.

Before

StatsD server connection failed (udp://hostdoesnotexiststalleverlol.stupidtld:8125)

After

StatsD server connection failed (udp://hostdoesnotexiststalleverlol.stupidtld:8125): (0) php_network_getaddresses: getaddrinfo failed: Name or service not known

As it presently stands, the `ConnectionException` is thrown when opening a socket fails and contains the system-level error code and message. This information, however, is only accessible if the `throwConnectionExceptions` flag is set and the original exception is propagated to the consumer. If the exception is disabled, then a user warning will be created using the `trigger_error()` function, which unfortunately does not carry an information from the exception, leading to inability to properly debug connection issues. With this change the original exception message will be appended to the produced warning.
@@ -40,7 +40,7 @@ function ($errno, $errstr, $errfile, $errline, $errcontext) use ($testCase, &$ha
$handlerInvoked = true;

$testCase->assertSame(E_USER_WARNING, $errno);
$testCase->assertSame(
$testCase->assertContains(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I am deliberately doing a substring match here, because the code and the message might differ per platform or the standard library in use.

@filakhtov filakhtov changed the title Propagate exception message via trigger_error() Propagate ConnectionException message via trigger_error() Jun 10, 2020
@serroba
Copy link

serroba commented Jun 11, 2020

It would be nice to have this added @marcqualie 🙏 🙇

@colinodell colinodell merged commit d291b36 into thephpleague:master Jan 15, 2022
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.

3 participants