-
Notifications
You must be signed in to change notification settings - Fork 124
Description
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 🙂