Skip to content

Comments

Add previous exception to StreamException on socket accept failure#17

Merged
sirn-se merged 1 commit intosirn-se:main-v2from
hotfix31:fix/add-previous-exception-on-stream-exception
Dec 24, 2025
Merged

Add previous exception to StreamException on socket accept failure#17
sirn-se merged 1 commit intosirn-se:main-v2from
hotfix31:fix/add-previous-exception-on-stream-exception

Conversation

@hotfix31
Copy link
Contributor

Hello! 👋

I encountered an issue while working with SSL/TLS sockets where error messages were not informative enough to diagnose configuration problems.

When stream_socket_accept() fails due to SSL/TLS configuration issues (e.g., inaccessible private key file), the original error message was lost and final users only saw: not accept on socket.

Now the exception includes the original error details: Could not accept on socket. (stream_socket_accept(): Unable to set private key file /certs/key.pem')`

This makes debugging SSL/TLS configuration issues much easier.

Thank you for maintaining this library! Let me know if you'd like any changes to this PR.

@sirn-se
Copy link
Owner

sirn-se commented Dec 13, 2025

Thanks for contribution!
Very reasonable change, but I need to figure out why unit tests are failing. Code looks fine to me so need to dig around a bit.

@sirn-se
Copy link
Owner

sirn-se commented Dec 14, 2025

Ok, it appears the missing cert file issue you're trying to provoke in the test does not cause exception until it has a stream accepted (which doesn't happen In the tests). So instead we end up with timeout exception in the test.

As I see it, there's no need to test specific errors that may occur, only that they are properly handled in the code.
So I would suggest;

  1. Remove the entire testAcceptWithInvalidSslContextShowsPreviousException test case
  2. On line 133 in the test, check that the exception (timeout) includes the error from lower-level error;
        $this->expectExceptionMessage('Could not accept on socket.');

to

         $this->expectExceptionMessage(
            'Could not accept on socket. (stream_socket_accept(): Accept failed: Operation timed out)'
        );

@hotfix31 hotfix31 force-pushed the fix/add-previous-exception-on-stream-exception branch from 65e18b6 to ab05ef1 Compare December 23, 2025 21:10
@hotfix31
Copy link
Contributor Author

I processed all your feedback, I preferred to use a match on the exception message.

@sirn-se sirn-se merged commit f46694e into sirn-se:main-v2 Dec 24, 2025
9 checks passed
@sirn-se
Copy link
Owner

sirn-se commented Dec 24, 2025

Released as v2.3.3. Thanks!

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.

2 participants