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.

How to forward errors using eventChannel?

See original GitHub issue

Using generator functions I know how to create a way to use exceptions by throwing errors:

function * foo () {
  yield 1
  yield 2
  throw new Error('oops!')
  yield 3
}

try {
  for (const n of foo()) {
    console.log(n)
  }
} catch (err) {
  console.log(`caught '${err.message}'`)
}
console.log('done!')

outputs:

1
2
caught 'oops!'

as expected.

However if I have an eventChannel, I do not see how I can easily throw errors from it:

const myChannel = function () {
  return eventChannel(function (emitter) {
     const s = someSource()
        .on('thing', emitter)
        .on('error', () => console.log('I do not know what to do here')
        .on('done', () => emitter(END))
     return () => s.cancel()
  }
}

Is there a way I can easily propagate errors from the eventChannel into my sagas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
yelouaficommented, Aug 10, 2016

Actually there is a [kind of] support for errors in take effects: if a take is resolved with an Error it will throw in the generator. For example

const myChannel = function () {
  return eventChannel(function (emitter) {
     const s = someSource()
        .on('thing', emitter)
        .on('error', () => emitter(new Error(...) ) /* put an Error instance */ 
        .on('done', () => emitter(END))
     return () => s.cancel()
  }
}

function* saga() {
  const chan = yield call(myChannel)
  while(true) {
    try {
      const thing = yield take(chan)
    } catch(err) {
      // emitting an Error will throw here
    }
  }
}

Note that emitting an error will not abort the channel by default, if you want to end the channel after an error you’ll have to close it explicitly (for example in the catch block of the Saga)

2reactions
shinimacommented, Jun 27, 2018

@adipascu Added to the todo list in #1478

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter: PlatformException using EventChannel
I am trying to implement EventChannel in my flutter app by am receiving the following error: ══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ...
Read more >
Handle One-Time Events with Kotlin's Channels - YouTube
In this video you will learn how you can send events that don't trigger again on screen rotation like with LiveData or StateFlow....
Read more >
NE06 - NASA Event Channel - IBM Cloud Video
In addition to the services they provide to IBM, certain IBM authorized partners may also use these cookies for their own purposes. This...
Read more >
Eventchannel Decoder Full Error
Substitute each <value> with your chosen value for each option and then restart the agent. With these new values the warning may go...
Read more >
emctl upload agent Failed With 'EMD Upload Error:full ...
EM 12c : emctl upload agent Failed With 'EMD Upload Error:full ... Backoff event : channel=Metadata expiration at 2017-07-10 02:28:41 BST
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