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

Unset _style during encode/decode of backend packets to avoid type mismatch errors #3776

Merged

Conversation

q0rban
Copy link
Contributor

@q0rban q0rban commented Nov 8, 2018

If a drush command uses a Robo collection (or perhaps just a Robo task—untested), and that command is invoked as a backend process, and that command fails, you may see an error like this:

 [error]  Drush command terminated abnormally due to an unrecoverable error.
Error: Uncaught Error: Unsupported operand types in /app/vendor/consolidation/log/src/LogOutputStyler.php:66
Stack trace:
#0 /app/vendor/consolidation/log/src/Logger.php(186): Consolidation\Log\LogOutputStyler->style(Array)
#1 /app/vendor/consolidation/log/src/Logger.php(171): Consolidation\Log\Logger->doLog(Object(Symfony\Component\Console\Output\StreamOutput), 'error', '', Array)
#2 /app/vendor/drush/drush/src/Log/Logger.php(174): Consolidation\Log\Logger->log('error', '', Array)
#3 /app/vendor/drush/drush/includes/drush.inc(454): Drush\Log\Logger->log('error', '', Array)
#4 /app/vendor/drush/drush/includes/drush.inc(428): _drush_log_to_logger(Object(Drush\Log\Logger), Array)
#5 /app/vendor/drush/drush/includes/drush.inc(488): _drush_log(Array)
#6 /app/vendor/drush/drush/includes/backend.inc(542): drush_backend_packet_log(Array, Array)
#7 /app/vendor/drush/drush/includes/backend.inc(454): drush_backend_parse_packets('\x00DRUSH_BACKEND:...', '', Array)
#8 /app/vendor/drush/drush/includes/backend.inc(1040): _drush_b in /app/vendor/consolidation/log/src/LogOutputStyler.php, line 66

After some debugging, it turns out this is because Robo\Log\ResultPrinter sets ['_style']['message'] to an empty string, which then gets encoded to json. When the "frontend" process then decodes this json, ['_style'] is decoded as a stdClass. This subsequently results in an unsupported operand error in Consolidation\Log\LogOutputStyler::style() as that function expects _style to be an array.

The attached patch strips _style from the packet prior to encoded and subsequent to decoding. You may wonder why the latter is necessary if the former is done, but remember that different versions of drush may be involved, so an older version of drush may happily send along the _style and recreate the same error on a newer version of drush. Cleaning up in both places should avoid this possibility.

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

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

LGTM

@greg-1-anderson
Copy link
Member

Needs test failure fixed, though. Not sure why it's failing; removal of style somehow affected linebreaks maybe?

@weitzman
Copy link
Member

weitzman commented Nov 9, 2018

I saw a similar failure in another PR so I dont think its caused by the change here.

@greg-1-anderson
Copy link
Member

Test failure must be intermittent; I re-ran the workflow and it passed.

@greg-1-anderson greg-1-anderson merged commit 7c228b0 into drush-ops:master Nov 9, 2018
@q0rban q0rban deleted the q0rban/remove-backend-packet-_style branch November 23, 2018 19:15
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.

None yet

3 participants