Skip to content

TypeError Twilio\Rest\Taskrouter\V1\Workspace\TaskInstance::__construct(): Argument #2 ($payload) must be of type array, null given #787

Open
@manurwx

Description

@manurwx

Issue Summary

This is the error we've been seeing in our prod environment

TypeError
Twilio\Rest\Taskrouter\V1\Workspace\TaskInstance::__construct(): Argument #2 ($payload) must be of type array, null given, called in /src/vendor/twilio/sdk/src/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php on line 85

Suspected cause

The payload (second argument) to TaskInstance constructor is generated by getContent() method in vendor/twilio/sdk/src/Twilio/Http/Response.php:22

all getContent() method does is to call json_decode() and according to PHP docs the only instances where it returns null is if it cannot decode the json string or max depth (default to 512) gets exceeded.
Either way seems like the SDK is not handling this edge case causing a TypeError exception when it happens.

Exception/Log

TypeError: Twilio\Rest\Taskrouter\V1\Workspace\TaskInstance::__construct(): Argument #2 ($payload) must be of type array, null given, called in /src/vendor/twilio/sdk/src/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php on line 85
#11 /vendor/twilio/sdk/src/Twilio/Rest/Taskrouter/V1/Workspace/TaskInstance.php(54): Twilio\Rest\Taskrouter\V1\Workspace\TaskInstance::__construct
#10 /vendor/twilio/sdk/src/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php(85): Twilio\Rest\Taskrouter\V1\Workspace\TaskContext::update
#9 /src/TwilioBundle/Lib/Api/TaskRouter/TasksApi.php(95): TwilioBundle\Lib\Api\TaskRouter\TasksApi::update
#8 /src/TwilioBundle/Service/TaskRouter/Conferences/ConferenceParticipantService.php(408): TwilioBundle\Service\TaskRouter\Conferences\ConferenceParticipantService::updateTask
#7 /src/TwilioBundle/Service/TaskRouter/Conferences/ConferenceParticipantService.php(97): TwilioBundle\Service\TaskRouter\Conferences\ConferenceParticipantService::createWorkerTask
#6 /src/TwilioBundle/Controller/TaskRouter/OutboundCallController.php(63): TwilioBundle\Controller\TaskRouter\OutboundCallController::receiveTaskRequest
#5 /vendor/symfony/http-kernel/HttpKernel.php(163): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#4 /vendor/symfony/http-kernel/HttpKernel.php(75): Symfony\Component\HttpKernel\HttpKernel::handle
#3 /vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\Kernel::handle
#2 /vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(35): Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner::run
#1 /vendor/autoload_runtime.php(35): require_once
#0 /public/index.php(5): null

Technical details:

  • twilio-php version: 6.44.4
  • php version: 8.1.13

Activity

tiwarishubham635

tiwarishubham635 commented on Apr 5, 2024

@tiwarishubham635
Contributor

Hi @manurwx! Can you please provide your code which you are using so that we can reproduce the error? Thanks!

manurwx

manurwx commented on Apr 5, 2024

@manurwx
Author

Hi @manurwx! Can you please provide your code which you are using so that we can reproduce the error? Thanks!

Hi, we use it in a commercial product so I can't share the code other than this line which triggers the error in our system:

return $this->client->taskrouter->v1->workspaces($this->workspaceSid)->tasks($taskSid)->update($attributes);

This is the error:

TypeError
Twilio\Rest\Taskrouter\V1\Workspace\TaskInstance::__construct(): Argument #2 ($payload) must be of type array, null given, called in /src/vendor/twilio/sdk/src/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php on line 85

It's pretty clear that the issue is in the implementation of update() method in vendor/twilio/sdk/src/Twilio/Rest/Taskrouter/V1/Workspace/TaskContext.php
It wrongly assumes that its internal $payload variable is always of array type, where in fact there are instances where it can actually be null. So when $payload happens to be null and it goes on to create a TaskInstance object passing a null payload as parameter it breaks.

added
priority: highNeeds immediate attention; blockers or critical or bug
status: work in progressTwilio or the community is in the process of implementing
and removed on Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: highNeeds immediate attention; blockers or critical or bugstatus: work in progressTwilio or the community is in the process of implementingtype: bugbug in the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @manurwx@tiwarishubham635

        Issue actions

          TypeError Twilio\Rest\Taskrouter\V1\Workspace\TaskInstance::__construct(): Argument #2 ($payload) must be of type array, null given · Issue #787 · twilio/twilio-php