Description
Describe the bug
Calling receiveMessage
on an instance of SqsClient throws an exception. We found this through a library upgrade triggered by Dependabot as it failed our CI. Here's the most minimal code to that triggers the exception.
public function testJsonFailure(): void
{
$awsSdk = $this->client->getContainer()->get(AwsSdk::class);
$sqsClient = $awsSdk->createSqS();
$result = $sqsClient->receiveMessage(
[
'MaxNumberOfMessages' => 1,
'QueueUrl' => "http://aws:4566/000000000000/internal_job_queue_dlq",
'WaitTimeSeconds' => 0
]
);
$this->assertNull($result->get('Messages'));
}
I did some digging and at https://github.com/aws/aws-sdk-php/blob/3.285.1/src/Api/Parser/PayloadParserTrait.php#L18, $json
holds a GuzzleHttp\Psr7\Stream
object and calling getContents
on that object revealed that it does not contain a JSON string but rather an XML string. This is the result of dump($json->getContents())
:
"<ReceiveMessageResponse><ReceiveMessageResult></ReceiveMessageResult><ResponseMetadata><RequestId>4PDN22TK8BPVAKSD643TKWBWUD8BHMKZIF8VNGJ3JLXTCLH8811J</RequestId></ResponseMetadata></ReceiveMessageResponse>"
This issue was not present in 3.285.0
Expected Behavior
The expected behaviour is that the parser receives a JSON payload and parses it successfully
Current Behavior
An exception happens with the following message gets thrown:
Aws\Api\Parser\Exception\ParserException: Error parsing JSON: Syntax error
Reproduction Steps
<?php
namespace MyApp\IntegrationTest;
use Aws\Sdk;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class InternalJobQueueTest extends WebTestCase
{
protected KernelBrowser $client;
/**
* @test
*/
public function testJsonFailure(): void
{
self::createKernel();
$this->client = self::createClient();
$awsSdk = $this->client->getContainer()->get(Sdk::class);
$sqsClient = $awsSdk->createSqS();
$result = $sqsClient->receiveMessage(
[
'MaxNumberOfMessages' => 1,
'QueueUrl' => "http://aws:4566/000000000000/internal_job_queue_dlq",
'WaitTimeSeconds' => 0
]
);
$this->assertNull($result->get('Messages'));
}
}
Possible Solution
No response
Additional Information/Context
No response
SDK version used
3.285.1
Environment details (Version of PHP (php -v
)? OS name and version, etc.)
PHP 8.2.4