Skip to content

[Messenger] Add previous to the exception output #52951

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

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.2
---

* Add `$previous` to the exception output at the `messenger:failed:show` command
* `WrappedExceptionsInterface` now extends PHP's `Throwable` interface
* Add `#[AsMessage]` attribute with `$transport` parameter for message routing
* Add `--format` option to the `messenger:stats` command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private function createCloner(): ?ClonerInterface
Caster::PREFIX_VIRTUAL.'file' => $flattenException->getFile(),
Caster::PREFIX_VIRTUAL.'line' => $flattenException->getLine(),
Caster::PREFIX_VIRTUAL.'trace' => new TraceStub($flattenException->getTrace()),
Caster::PREFIX_VIRTUAL.'previous' => $flattenException->getPrevious(),
Copy link
Member

Choose a reason for hiding this comment

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

Will it work this way as getPrevious() returns a FlattenException instance and not a scalar value? And what about calling getAllPrevious() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will it work this way as getPrevious() returns a FlattenException instance and not a scalar value?

It shows the trace fine in the terminal, and gives all the information needed for further debugging.

Example:

previous: App\Exception\CustomViolationException^ {#1
    message: """
      SQLSTATE[23000]: Integrity constraint violation: ...
      """
    code: 1062
    file: "/app/src/Service/ExampleService.php"
    line: 167
    trace: {
      /app/src/Service/ExampleService.php:167 {
        App\Service\ExampleService->updateStuff(array $updateCollection): void^
        ›
        › throw new CustomViolationException(
        ›     message: $e->getMessage(),
      }
      /app/src/Service/ExampleServiceTwo.php:94 { …}

And what about calling getAllPrevious() instead?

I didn't know about getAllPrevious() but after trying it out I don't see much difference between the two except for notation.

getPrevious

previous: PDOException^ {
  message: "SQLSTATE[23000]: Integrity constraint violation: ...
}

getAllPrevious

previousAll: [
  PDOException^ {#3
    message: "SQLSTATE[23000]: Integrity constraint violation: ...
    ...
  },
  PDOException^ {#3}
]

As it seems the same to me, what do you think is best to use?

];
}]);

Expand Down
Loading