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

Consumer::handleError() TypeError for ForkCurl queue consumer #238

Open
JeroenBakker opened this issue Dec 20, 2024 · 0 comments · May be fixed by #239
Open

Consumer::handleError() TypeError for ForkCurl queue consumer #238

JeroenBakker opened this issue Dec 20, 2024 · 0 comments · May be fixed by #239

Comments

@JeroenBakker
Copy link

JeroenBakker commented Dec 20, 2024

Hi there, we ran into a TypeError on production which turned out to be caused by the error handling of the ForkCurl consumer.

The full error error trace is:
TypeError: Uncaught TypeError (500): Segment\Consumer\Consumer::handleError(): Argument #2 ($msg) must be of type string, array given, called in /var/www/html/vendor/segmentio/analytics-php/lib/Consumer/ForkCurl.php on line 78 in /var/www/html/vendor/segmentio/analytics-php/lib/Consumer/Consumer.php:92
#0 /var/www/html/vendor/segmentio/analytics-php/lib/Consumer/ForkCurl.php(78): Segment\Consumer\Consumer->handleError()
#1 /var/www/html/vendor/segmentio/analytics-php/lib/Consumer/QueueConsumer.php(113): Segment\Consumer\ForkCurl->flushBatch()
#2 /var/www/html/vendor/segmentio/analytics-php/lib/Consumer/QueueConsumer.php(92): Segment\Consumer\QueueConsumer->flush()
#3 /var/www/html/vendor/segmentio/analytics-php/lib/Client.php(54): Segment\Consumer\QueueConsumer->__destruct()
#4 [internal function]: Segment\Client->__destruct()
#5 {main}

In short: exec() outputs an array of lines and handleError() only accepts a string.
This causes a TypeError due to strict_types, and the actual error that was being handled becomes very hard to debug since all output is sent to /dev/null without debug mode.

Since the output of exec() is an array of all of the output lines, simply joining them together with newlines reconstructs the actual output as a string, which makes this all work as intended again.

A side note: it feels very risky to use strict types without some form of static analysis such as phpstan. Level 5 of phpstan easily detects type errors such as this and it would be a valuable addition to a package like this that has millions of installs on production software 🙂

@JeroenBakker JeroenBakker linked a pull request Dec 20, 2024 that will close this issue
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 a pull request may close this issue.

1 participant