PSR-3 context exception key, change to allow `Throwable`

118 views
Skip to first unread message

Sasezaki

unread,
Jul 4, 2021, 4:35:10 AM7/4/21
to PHP Framework Interoperability Group
Hi.

I have suggestion for psr-3 context's key 'exception'.
Could be change allow `\Throwable` to accept ?

current psr-3
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
> 'exception' key is actually an Exception.

I think this was designed for PHP 5 age.

But, recent Monolog 's code is
> if (isset($context['exception']) && $context['exception'] instanceof Throwable) {
https://github.com/Seldaek/monolog/blob/2.2.0/src/Monolog/Handler/RollbarHandler.php#L92

Other LoggerInterface implementer would be confused.
"should it be strictly `\Exception` ? or `\Throwable`  ?".

--

And  from strict analysis tool usage (array-shapes stubs), it also needs to be clear  \Exception or  \Throwable.

I have several implmentaion as example,

array{exception?: \Exception}  $context
https://github.com/struggle-for-php/sfp-psalm-psr-log-plugin/blob/0.2.0/stubs/LoggerInterface.php

array{exception?: \Throwable}  $context
https://github.com/struggle-for-php/sfp-psalm-psr-log-plugin/blob/0.2.0/throwable-stubs/LoggerInterface.php


Larry Garfield

unread,
Jul 4, 2021, 10:54:40 AM7/4/21
to PHP-FIG
You are correct, PSR-3 was developed around the PHP 5.4 era. I would be fine with adding an Errata to the metadoc that says "Throwables generally". That would require a PR and a Core Committee vote.

Note that PSR-3 doesn't have a metadoc yet. :-) It's that old. There's another vote in progress to add types to the interface packages that includes adding a metadoc file. I'd say wait until that finishes (it looks like it's going to easily pass), and then it will be possible to add another errata to it in a second step.

--Larry Garfield

Sasezaki

unread,
Jul 6, 2021, 9:20:49 AM7/6/21
to PHP Framework Interoperability Group
Hi, Larry.

Thanks you for checking. And I'm glad to hear considering.


2021年7月4日日曜日 23:54:40 UTC+9 Larry Garfield:
Reply all
Reply to author
Forward
0 new messages