Skip to content
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

[NormalizerFormatter] Avoid throwing an exception when the toString call fails #1868

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

VincentLanglet
Copy link
Contributor

HI @Seldaek

This is an improvement of #673

When a __toString method call throws an exception (which should occurs as few as possible), the Normalizer is throwing an exception too. I believe this behavior is wrong because:

  • I cannot say monolog to prefer the default behavior over the __toString method
  • If I wouldn't have a __toString method, it would have work correctly

Also, I have the following situation when using DoctrineFixtureBundle:

  • I wrote a bug in my fixtures
  • An exception is thrown
  • During this process, monolog try to do some logs
  • For the logs, he look for FooObject::__toString() method
  • This method return the name of the FooObject which require a database request (because of doctrine lazy proxy)
  • The entity is not found in database (of course, since the fixture loading failure)
  • The __toString throws an exception
  • Monolog crash
  • I get the monolog failure instead of the doctrineFixture one to debug correctly my work.

As soon as I comment the toString method in my entity, I get the correct error.
Imho, if monolog cannot use the toString method, he shouldn't change the "error behavior" and fallback to jsonEncode like the tostring method doesn't exist.

WDYT ?

@VincentLanglet
Copy link
Contributor Author

Friendly ping @Seldaek if you find some time to take a look :)

@Seldaek Seldaek merged commit c4ba76a into Seldaek:main Apr 12, 2024
@Seldaek
Copy link
Owner

Seldaek commented Apr 12, 2024

Thanks yeah probably makes sense to avoid failures.

@Seldaek Seldaek added this to the 3.x milestone Apr 12, 2024
@Seldaek Seldaek added the Bug label Apr 12, 2024
@VincentLanglet VincentLanglet deleted the avoid-to-string-exception branch April 12, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants