question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cancellation too presumptive?

See original GitHub issue

Just some food for thought…

Nevertheless, a warning is logged into the console in case a cancelled task omitted to handle a cancellation exception.

I have quite a few instances where one saga spawns a fetcher function, and that fetcher func then invokes the actual function doing the xhr. This is to keep functions lean and “doing one thing”. Maybe I want to transform the parameters or data before/after fetching, or maybe I want to check status codes and validate returned values versus nulls, etc.

    function doFetch(params) {
        yield xhr(url, params)
    }

    function* fetch(params) {
        const { statusCode, body } = yield call(doFetch, params)

        if (statusCode > 499) {
            return null
        }

        const data = body.someData

        // ... do some transformations on the data

        return {
            transformedData
        }
    }

    function* fetchSomeStuff() {
        yield put(START_FETCH)

        // ...maybe configure some parameters

        const results = yield call(fetch, params)

        // ...do some data transforms on results

        yield put(FETCH_SUCCESS, results)
    }

When I want to sure up this code with some error handling, in order to avoid a console.warn by redux-saga I have to put in a try/catch for every step along the saga. This is fairly inconvenient to have to handle a thrown saga cancelled exception at every invocation, particularly because I only want to use the catch to “cleanup” in one of the cases:

    function doFetch(params) {
        let req
        try {
            return (yield req = xhr(url, params))
        } catch (e) {
            if (e instanceof SagaCancellationException) {
                req.abort()
            } else {
                throw e
            }
        }
    }

    function* fetch(params) {
        // doesn't have to handle errors, since there's nothing to do and the
        // caller handles anything that might be thrown... 
        try {
            // ... same code as above
        } catch (e) {
            // there's nothing to do here except stop the console.warn() from showing up
        }
    }

    function* fetchSomeStuff() {
        try {
            yield put(START_FETCH)

            // ...maybe configure some parameters

            const results = yield call(fetch, params)

            // ...do some data transforms on results

            yield put(FETCH_SUCCESS, results)
        } catch (e) {
            // capture SagaCancellationException, but throw any js errors
            if (!e instanceof io.SagaCancellationException) {
                console.error(e)
            }
        }
    }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yelouaficommented, Jan 25, 2016

I’m thinking of making this an opt-in behavior. Provide some config argument, so the developer can choose to disable the console warnings

0reactions
yelouaficommented, Jan 30, 2016

@aft-luke yes. Included with the new 0.6.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Presumptive vs presumptuous - Grammarist
Presumptuous means (1) going beyond what is proper, or (2) excessively forward. One who is presumptuous presumes too much.
Read more >
Presumptive Eligibility - Indiana Medicaid: Members - IN.gov
Your PE will be discontinued if you do not apply for coverage by the last day of the month following the month your...
Read more >
Termination of Collection Action, Write-off and Close-out ...
a rebuttable presumption of this identifiable event occurs when the creditor agency does not receive any payment on a debt for a 36...
Read more >
VA Claim Exam: Frequently Asked Questions (FAQs)
If you have any questions concerning your claim exam or need to cancel or reschedule your appointment(s), please contact the contract vendor that...
Read more >
Absences that are too long and how to cure them
When an LPR has been abroad continuously for more than one year, the presumption is that abandonment has occurred. 8 CFR § 211.1(a)(2)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found