Feature Request: Implement `__debugInfo()` on `Aws\Command` to prevent massive `var_dump` / log output
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start at Aws\Command and reproduce the example.php scenario that dumps an AwsException containing a command. Implement the requested reduced debug representation for the command, preserving the essential name and data while avoiding recursive handler and API model output. Done means var_dump($e) no longer produces the massive nested output described in the issue.
Written by the indexing model from the issue text.
Description
Describe the feature
I would like to request implementing the magic method __debugInfo() on Aws\Command (and potentially related internal objects. e.g. Aws\HandlerList) to suppress excessively large outputs when using var_dump(), print_r().
When an exception occurs (e.g. Aws\Exception\AwsException), dumping the exception via var_dump($e) or passing it to certain loggers results in extremely large output.
This is mainly because AwsException holds an instance of Aws\Command, which references heavy nested service handlers and shape definitions.
Use Case
# example.php
require_once __DIR__ . '/vendor/autoload.php';
$s3Client = new Aws\S3\S3Client([/* ... */]);
try {
$s3Client->getObject([
'Bucket' => 'test-bucket',
'Key' => 'notfound.txt',
]);
} catch (Exception $e) {
var_dump($e);
}
Running the above script produces gigabytes of text output because var_dump recursively traverses all properties inside Command and its associated API models/handlers.
This makes print-debugging almost impossible and can easily overwhelm logging storage/buffers in production or development environments.
$ php example.php > out.txt
$ ls -l | grep out.txt
-rwxr-xr-x 1 user group 26626988124 Oct 2 13:52 out.txt
Proposed Solution
Implement __debugInfo() in Aws\Command so that only essential debug details (such as command name and passed arguments) are returned during inspection.
By defining __debugInfo(), PHP will use this reduced array for var_dump() / print_r() instead of recursively dumping all internal property references.
for example:
namespace Aws;
class Command implements CommandInterface
{
// ...
public function __debugInfo(): array
{
return [
'name' => $this->name,
'data' => $this->data,
];
}
}
Then, Output is below:
$ php example.php > out.txt
$ ls -l | grep out.txt
-rwxr-xr-x 1 user group 782744 Oct 2 13:57 out.txt
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
SDK version used
3.399.0
Environment details (Version of PHP (php -v)? OS name and version, etc.)
PHP 8.3.31/Rocky Linux 10.2
- Dominant language
- PHP
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 17h 23m
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-sdk-php
-
Event stream decoder reports a checksum mismatch when the checksum is read in partsPossibly taken @lazerg claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
aws/aws-sdk-php#3371 ·
Maintainers usually reply within 1 day
-
AssumeRoleCredentialProvider replaces non-RuntimeException failures with TypeErrorPossibly taken @lazerg claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
aws/aws-sdk-php#3370 ·
Maintainers usually reply within 1 day
-
announcement
Difficulty 4/5 3-5 days Newbie friendliness 12/100
aws/aws-sdk-php#3369 ·
Maintainers usually reply within 1 day
-
bug needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 30/100
aws/aws-sdk-php#3364 ·
Maintainers usually reply within 1 day
-
LambdaClient::invokeWithResponseStream fails because CURLOPT_TCP_KEEPALIVE is passed to Guzzle StreamHandlerPossibly taken @stobrien89 claimed this 36 days ago. Openbug needs-triage
aws/aws-sdk-php#3345 · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
woocommerce/woocommerce-google-analytics-integration#699 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ProfessionalWiki/NeoWiki#1675 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100