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
Consider adding safe
effect wrapper
#1250
Comments
@Andarist could you describe what is the idea behind "safe" effect? |
Im not yet exactly sure about the API, but one idea is to: const safe = effect => (effect[SAFE] = true)
function* someSaga() {
// where result is of type Error or Result
const result = yield safe(call(someAPI, arg1))
// in case of an error would die gracefully instead of failing the parent
yield safe(fork(otherSaga, arg2))
} In this variant Other way of implementing it would be require implementing equivalent of: function* safe(effect) {
try {
return { result: yield effect }
} catch (err) {
return { err }
}
} In this variant |
I can try do this |
Cool! Seems to be that second variant of what I have proposed (no |
I'm using next pattern in my projects, that's kinda 2nd version function* safe(effect) {
try {
return { result: yield effect, error: null }
} catch (error) {
return { result: null, error }
}
} |
@Andarist interested in working on this enhancement |
@younesmln go ahead, if you need any help - please just ask |
@restrry how do you use it? I tried something like that:
but still only the top level error handler is called and not the specific of the |
@jaulz I think the problem in the snippet that it uses
https://github.com/redux-saga/redux-saga/tree/master/docs/api#spawnfn-args could you try to use |
I have tried to implement via @restrry solution however I get the following error:
this happens when i try to use it at a core level, basically my goal being to wrap my entire process:
I have also tried without fork and even though it felt wrong I've also tried wrapping the takeLatest instead plus also i've tried not using fork given that takeLatest already does this (just tryin anything). All don't work and I'm pretty sure had the basically the same error message. Perhapse you could explain why we return { result, error} if there is one so I can attempt to understand the underlying functionality? Also maybe I'm just using this wrong? For now I am just going to wrap the code I know is likely to crash in a try catch, my main reason for looking into this however is that I don't plan on ever actioning the crash (its fine if this happens) so I would rather enrich my saga via composition instead of having to dump code into a working function. |
@fgfmichael the idea is: don't yield your effects immediately inside your function, let's another "safe" function do it. Example:
|
Hi, Is anyone working on this issue @Andarist? |
Hi, everyone)) I'm honored to take this issue. I already have some code written for exactly the same purpose) |
Hey, @Andarist ) |
If somebody wants to work in it - let me know. We can then establish how this would work
The text was updated successfully, but these errors were encountered: