Fix TypeError when Response.getContent() returns null in Taskrouter Context classes#873
Draft
Fix TypeError when Response.getContent() returns null in Taskrouter Context classes#873
Conversation
|
Co-authored-by: tiwarishubham635 <59199353+tiwarishubham635@users.noreply.github.com>
Co-authored-by: tiwarishubham635 <59199353+tiwarishubham635@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Check the issue @twilio/twilio-php/issues/787 and draft a PR that resolves this issue
Fix TypeError when Response.getContent() returns null in Taskrouter Context classes
Jul 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
Users were experiencing a
TypeErrorin production when using Taskrouter API methods:This error occurs when
Response::getContent()returnsnullinstead of an array. ThegetContent()method callsjson_decode()which returnsnullwhen:Root Cause
Multiple Taskrouter Context classes were passing the raw result from
$this->version->fetch()and$this->version->update()directly to Instance constructors that require anarraytype:Solution
Added null coalescing operator (
?? []) to provide an empty array fallback when the payload is null:This prevents the TypeError while maintaining normal functionality when valid JSON is returned. The
Values::array_get()method used by Instance classes already handles missing keys gracefully, so an empty array is a safe fallback.Files Changed
TaskContext.php- Fixedfetch()andupdate()methodsWorkflowContext.php- Fixedfetch()andupdate()methodsWorkerContext.php- Fixedfetch()andupdate()methodsActivityContext.php- Fixedfetch()andupdate()methodsTaskQueueContext.php- Fixedfetch()andupdate()methodsTesting
Fixes #787
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608/usr/bin/php8.3 -n -c /tmp/1hRz2D /usr/bin/composer install(http block)https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c/usr/bin/php8.3 -n -c /tmp/1hRz2D /usr/bin/composer install(http block)https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af/usr/bin/php8.3 -n -c /tmp/1hRz2D /usr/bin/composer install(http block)https://api.github.com/repos/symfony/stopwatch/zipball/5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd/usr/bin/php8.3 -n -c /tmp/1hRz2D /usr/bin/composer install(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.