Pool Exception Handler: Typehints #445
Replies: 2 comments 3 replies
-
I opted for mixed, because in theory you can pass mixed to I thought about at least setting Throwable, but can't remember why I didn't off the top of my head. The reason for the extra arguments can be seen here: https://github.com/guzzle/promises/blob/6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8/src/EachPromise.php#L183 I won't have access to my computer for another two weeks, or so. |
Beta Was this translation helpful? Give feedback.
-
Thanks! Appreciate the quick response (especially when you're away from your computer...) Both very helpful pointers. Would I be correct in thinking that as long as all "promise rejection" logic (at least, when dealing with I've spent some time today looking through Guzzle code, but don't feel like I have an answer to the above yet... Just an FYI (incase this affects how much time you spend on this) - this isn't a big deal to my project, nor is it time sensitive (at all). I am however, finding it quite interesting to look into! Finally, to save me looking it up again: can pass mixed to PromiseInterface::reject(). |
Beta Was this translation helpful? Give feedback.
-
Hey, first of all thanks for the library - it’s saved me many hours of work 🙂
I’ve recently had a small type checking issue (hopefully the right explanation?), when using the
Http\Pool
’swithExceptionHandler
method (as explained in the docs)The issue is reported by PhpStan, and is as follows:
Essentially, complaining that I’ve passed a callable with first argument
FatalRequestException|RequestException
when the expected type ismixed
. Basically, the callable may be used with a first argument of typemixed
, so declaring it as only allowingFatalRequestException|RequestException
is unacceptable (and has potential to cause a type error).I was going to suggest this may be an upstream issue from
Guzzle
, as this is built around around theirpromises/src/EachPromise.php
, and their$onRejected
property only declares a type ofcallable|null
(so how could saloon know any more thanmixed
?). However, the other arguments for this callable are more specific (thanEachPromise
declares)...I’m a little unsure where to go from here, I don’t know anywhere near enough to confidently say (or figure out whether) this typehint could be narrowed (
Exception
would fit my use case, but if it can be more specific I think it should be). Alternatively, does my code need to be able to handle nonException
values? And if so do the docs need updating?Possibly relevant? Sugggestion of using throwable in Guzzle github
Beta Was this translation helpful? Give feedback.
All reactions