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.

errors and async consequence

See original GitHub issue

Hello,

the current API for errors is

errors(function(err, push) {})

so we can push one or more values at the current location of the stream if we already know those values.

When you need an async operation in order to know how to react to an error, how would you organize your streams ? a consume custom transform ? a sort of push(stream) + sequence

I wonder if there is room for an API of the style

errors(function(err, push, next) {})

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
vqvucommented, Aug 29, 2017

I would just use consume for this. The onError transform suggested in this issue isn’t implemented.

stream.consume((err, x, push, next) => {
  if (err) {
    // You can use toCallback if logErrorAsync must return a Highland stream,
    // and you can't access the underlying promise.
    logErrorAsync(err)
        .then(() => next())
        .catch((loggingError) => {
          push(loggingError);
          next();
        });
    push(err);
  } else {
    push(null, x);
    if (x !== _.nil) {
      next();
    }
  }
});

You can extract this into a through-transform if you need to use it in multiple places. There are examples in the docs.

0reactions
cantide5gacommented, Aug 28, 2017

This is really old now, but exactly what I’m dealing with currently. @vqvu, @jeromew et al, what is the approach you use now-a-days?

My case is that I need to log errors in an async fashion (specifically to an AWS S3 bucket) and push the error back on the stream so that it can go and fail. Additionally, if the logging has issues, I push a new error that does a couple extra steps. The async stuff is within a promise wrapped by highland.

Is there an example in the docs of a pattern that covers this? Or alternative approaches?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Errors With Async Await - Thenable
The problem with using a traditional promise .catch() method is that it doesn't branch the code if an error occurs. The result variable...
Read more >
Async/Await Error Handling - Beginner JavaScript - Wes Bos
We will talk about error handling strategies for async await in this lesson. Because there is no .then() that we are chaining on...
Read more >
The hard error handling case made easy with async/await
Let me show a surprisingly trivial looking async/await code which is actually hard to implement correctly with Promises. There, what was so hard...
Read more >
How to Simplify Asynchronous JavaScript using the Result ...
The Result-Error Pattern helps you hide try-catch blocks, simplify error handling, and encapsulate cleanup operations.
Read more >
Async await usage and error handling woes - Stack Overflow
A practical answer for beginners in async/await and error handling. You cannot use await syntax outside of a function that is not declared...
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