-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[11.x] feat: Adding catch callback to Pipeline #54237
base: 11.x
Are you sure you want to change the base?
Conversation
Have you considered what should happen in cases where multiple calls to the catch method exists? |
Drafting pending comment above @mathiasgrimm |
I works the same way as the finally method. If called more than once it will replace the previous callback. |
So, if multiple callbacks would be wanted, both |
The Finally is already merged and released, including all tests. I only added an "out of scope" test for the |
One thing, however, that would make sense for (new Pipeline(new Container))
->send($std)
->through([
function ($std, $next) {
return $next($std);
},
function ($std) {
throw new ExceptionB('My Exception: '.$std->value);
},
])->catch(function ($std, ExceptionA $e) { // this is not called
Log::error('Exception A', $std);;
return $std;
})->catch(function ($std, ExceptionB $e) { // this is called
$std->value = 100;
return $std;
})->catch(function ($std, ExceptionB $e) { // this might also be called
$std->value = 100;
return $std;
})->catch(function ($std, Throwable $e) { // default case if nothing else is matched
$std->value = 100;
return $std;
})
->then(function ($std) {
return $std;
}); |
Interesting @shaedrich. I've looked at other parts of the framework, such as:
And they all allow for multiple catch callbacks. I've also looked into the only implementation of
It also uses an array for callbacks. We need to be consistent throughout the entire framework. I think the first thing we need to address is to make sure the Pipeline Secondly, I see your suggestion as a potentially good idea, but it would make sense to be a separate PR that would introduce this feature of "scoped catch" for all catch methods. To summarize what I think needs to be done now:
What do you think @taylorotwell ? |
Sounds good, @mathiasgrimm btw, the scoped catch was inspired by how exception handling is done |
Adding a catch callback to the Pipeline