Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 18 23:34
    hubertokf opened #2140
  • Nov 17 20:28
    Slapbox opened #2139
  • Nov 17 11:18
    egorovsa commented #884
  • Nov 17 07:28
    Andarist commented #1828
  • Nov 16 23:08
    Slapbox commented #1828
  • Nov 16 07:26
    JasonXiaoSpace commented #1883
  • Nov 15 15:09
    Andarist commented #1800
  • Nov 15 11:29
    gadiGuesty commented #1800
  • Nov 12 11:11
    sofly commented #2138
  • Nov 11 04:16
    BuangHosen opened #2138
  • Nov 10 23:23
    d65yan commented #970
  • Nov 10 22:33
    Andarist commented #970
  • Nov 10 20:47
    gkielyellation commented #970
  • Nov 09 23:17
    Andarist closed #2137
  • Nov 09 23:17
    Andarist commented #2137
  • Nov 09 15:20
    MaxToyberman edited #2137
  • Nov 09 15:19
    MaxToyberman opened #2137
  • Nov 09 12:24
    abdymm commented #2098
  • Nov 09 10:32
    aepp commented #1064
  • Nov 08 20:33
    Avizura commented #2127
Rishi Kumar Chawda
@rishichawda
Hi @all, I'm having trouble deciding how to handle global errors on my sagas and I was unable to find an elegant solution to it. Currently all my sagas have a huge try block which sends errors to sentry in its catch block if there's any error. Can someone please suggest me any better solution for this? I even followed up a few issues on the GitHub repo and stackoverflow but unfortunately I couldn't find something I can say can be considered as best practice. So I wanted to know how everyone else handles this. Any help, advice or suggestion is appreciated! Thanks in advance and I hope everyone is having a nice day!
A Flores
@unflores
This doesn't surprise me, the nature of saga calls makes me think more of error catching on an individual basis. If you are hitting an api, then you'll have to deal with 400 etc. That type of thing should probably be dealt with on a case by case basis. If you are looking for a global catch-all, I found this in github: redux-saga/redux-saga#1672
It might correspond to your needs @rishichawda
Rishi Kumar Chawda
@rishichawda
@unflores I am aware of that issue and solution given there, but as you can see that makes the root saga terminate. Which I don't want. I want to handle the errors and restart / rollback etc if anything like that happens.
Rishi Kumar Chawda
@rishichawda
Also, I'm using apisauce for calls to my api server so everything in the requests part is handled very well right now. What I wanted to do is make sure I handle possible scenarios that might happen in the production which cannot be reproduced so well manually. Like what if there's an inconsistent state or what if the data is corrupted or what if something happens on put or call. I need to handle those errors too. I'm not concerned about anything breaking in the UI since I'm having error boundaries for them but I need to make sure everything works fine with sagas too. Right now I pretty much have one try catch block in every saga which kind of feels redundant and doesn't look pretty to me. So I was looking for an elegant way to do that.
How do you handle errors in your saga btw? @unflores
A Flores
@unflores
@rishichawda we catch them in individual sagas. For me that makes the most sense, anything that gets up to the mainSaga error handler is more of a "catastrophic" error, I don't want to handle it b/c I wasn't expecting it. I just want to log it somewhere so I can deal with it later. I treat it as equivilant to a 500 from an api.
Evan Meeks
@evanmeeks
@rishichawda apisauce NICE!
@rishichawda I've been looking for something solid like this
Rishi Kumar Chawda
@rishichawda
@evanmeeks glad you found it useful. it is my go to solution for setting up things quick!
msaraac
@msaraac
Hello guys how can I get cookie with in the reducer
Chris LeBlanc
@spacesuitdiver
Hello, I'm having trouble understanding how/when to use fork/all... when registering "rootSagas"... I'm using redux-saga-requests and my sagas are broken into redux "duck" like modules, any duck may fire redux saga requests.
What I'm currently facing though I think is unrelated... for some reason my takeLatest from one module is not responding to another's action fired I think
in my rootSaga I have yield createRequestInstance(); yield watchRequests(); all([fork(duck1), fork(duck2)]);
Chris LeBlanc
@spacesuitdiver
I guess to make a digestible question, what's the relationship between something that is forked and takeLatest?
Tormen Raßmann
@trassmann
takeLatest takes the action from the standard channel and forks a new task, if the same action is fired again while an old task is still running it gets cancelled AFAIK
and a forked task is just a forked task
you need to yield the all effect as well though
yield all([fork(duck1), fork(duck2)]);
Mladen Petrović
@mladenp
Hey all, i am getting error call: argument of type {context, fn} has undefined or null while trying to compose sagas.
I have no idea whats wrong
Monteiro Steed
@SteedMonteiro

Hello @everyone

We’re looking for React/React Native engineers to work as part of our community. We have multiple projects and missions, where you choose on what you want to work. There is no hiring process, so keep your resumate... it’s an open organisation, here only our work matter :)

StudioLabs is a 100% remote international company, originally founded in Paris, France. We help companies develop their applications by providing them skills of developers and designers from around the world. We believe in living a life of freedom, where freelancers can choose their missions.

Join our community here:http://bit.ly/2w2BHYO

rwong
@foodforarabbit
@rishichawda hey I hope this reply isn't too late, but you can have sagas call each other in a chain, so you can consolidate all your generic error handling in one place. For example, instead of takeEvery(GET_RESOURCE_ACTION, getResources) and have getResources call the api directly, you can have getResources handle composing parameters / handling api response. In the middle, getResources might yield call callAndHandleApiErrors which deals with figuring out which api-specific things you need like headers, endpoints, etc... and dealing with api-level response errors. And within callAndHandleApiErrors you might have yet another saga that does the actual fetch call itself, and handles network-level issues. For example, if you want to auto-retry an api call X amount of times, you might pass that as a parameter down to the fetch* saga which can handle retrying your api call, and if it fails X times then it can dispatch an error and return something to the callAndHandleApiErrors saga so that it knows that it can proceed (e.g. just return null or something).
vitalicwow
@vitalicwow
Using redux-saga-test-plan, any idea why my generator that returns a Promise would cause test to time out? Getting error: "Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout."
3kgoldie
@3kgoldie
Can someone explain how the saga middleware works under the hood? Like I understand how middlewares work and I understand what take/takeEvery ect does, but I don't understand how the saga middleware does its job of getting the actions to the right sagas. Or maybe point me to a resource that explains it?
Ahmad R
@harvester-klirk
hi guys , how do i pass an argument from the action creator to my saga ?
AmyBlankenship
@AmyBlankenship
In the documentation on task cancellation (https://redux-saga.js.org/docs/advanced/TaskCancellation.html), it shows how to test that a task was cancelled, but it seems to me to be waaay more important to test that the code in the task that actually does the real cancellation (if yield(cancelled) {abortController.abort()} for example) runs. But I haven't been able to figure out how you create a generator as a task and cancel it so that I can test this. I think I understand how to spy on the constructor for AbortController so I can look at what happened--I just have no clue how to make it happen in a test scenario. The code would normally get cancelled by takeLatest.
@harvester-klirk , if you're asking what I think you're asking, the action itself will be the argument, and you'll look at its properties to determine what you should do. In addition, you can get access to the state using select() to fill in any gaps.
AmyBlankenship
@AmyBlankenship
For anyone else wanting to test the finally logic in a canceled saga, I found the answer here https://stackoverflow.com/questions/46166401/unit-testing-redux-saga-task-cancellation https://github.com/redux-saga/redux-saga/issues/266#issuecomment-216087030. Hope this helps someone
Matti Järvinen
@nemeciii_twitter
Kinda related to @AmyBlankenship ´s question. I'm testing a full saga with runSaga. How would I add another action in there so I can test that it cancels the previous one?
Alan.He
@alanhg
for v1.o, catch not work? const rootTask = sagaMiddleware.run(rootSaga)
rootTask.done.catch(...)
Alan.He
@alanhg
Alan.He
@alanhg
anybody know the issue
Aleksander Vognild Burkow
@aleksanb
@gilbsgilbs i'm having a look at your dtslint branch
I'm not having any trouble running the tests, and think i might be getting other erors than you described
i get straight-up normal errors:
Error: /Users/aleksandervognildburkow/Projects/redux-saga/packages/core/types/ts3.5/channels.test.ts:24:1
ERROR: 24:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 32:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 45:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 47:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 51:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 56:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 58:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 82:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 90:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 99:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 112:1   expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 116:1   expect  TypeScript@next: Expected an error on this line, but found none.
Alan.He
@alanhg

In order for the execution exception of an effect to not affect the whole, I created a wrapper function. For example, the following adds safety to each effect, which solves the problem.

But if my effect is very large, it is very time consuming and not elegant to manually increase the safety. I want to know if there is any way, such as a loop function to automatically add safety to each effect, which makes the code more beautiful.

wrapper function

import { call } from 'redux-saga/effects';

export function safe(sagaFn) {
  return function* (action) {
    try {
      return yield call(sagaFn, action);
    } catch (e) {
      console.error('[react-demo | Saga Unhandled Exception] This error should be fixed or do some pre check in saga effects function.');
      console.error(e);
    }
  };
}

saga.js

function* mySaga() {
    yield takeEvery('USER_FETCH', safe(fetchUserEffects));
    yield takeEvery('TEST_SAGA', safe(testSagaEffects));
    yield takeEvery('TEST_SAGA', safe(testSagaEffects2));
}
@aleksanb
Gilbert Gilb's
@gilbsgilbs

@aleksanb Just came across your message. Thanks for reaching out! The errors you were pointing out occurred because TS wasn't able to resolve some types and was using any type as a replacement. So this was actually highly related to the issue I had.

As I said in the PR, I finally found a way to debug and fix it and the PR got merged into master :tada: . Unfortunately, it doesn't seem to work on @Andarist machine and he's unable to release, not sure why. If you want to give it a try 🤷‍♂️ .

@Andarist whenever you feel like it, we can spend some time to try to figure out what's wrong. Just tell me.
Aleksander Vognild Burkow
@aleksanb
amazing!
Great to see this being released now.
I upgraded our local project, the only thing missing now is for us to get const someresult = yield call(someTypedFunction) to work, but that's blocked on typescript adding more support, right?
Mateusz Burzyński
@Andarist
Yes
This cant yet be expressed in TS
There has been discussion around adding eslint plugins with autofixer that would annotate those for u
Prateek Chachra
@prateekchachra
Hey guys
needed some help
Trying to setup redux saga
The method in 'takeLatest' is being called more than 6000 times in one go, which is hanging my app