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.

Is the "onEnd" callback mandatory?

See original GitHub issue

I have a use-case where I want to essentially pull the stream out of these callbacks before I use it.

return new Promise((resolve, reject) => {
  req.multipart(
    (field, filestream, originalFilename, encoding) => {
      resolve(filestream);
    },
    (err?: Error) => {
        // i don't care what happens here, i handle it elsewhere
    },
    {
      limits: {
        fileSize: TWO_MEGABYTES,
        fields: 0,
        files: 1,
      },
    },
  );
}

I’m trying to figure out if I have to worry about the onEnd call back as it just seems really verbose. I’d rather get access to the file that’s being uploaded and resolve/pipe it somewhere else and handle the errors there. As it looks now, it appears I can do that but also need to handle a seemingly arbitrary case around the onEnd callback. Usually I notice the events happen in the following order, but I’m wondering if under certain circumstances that could change:

  1. resolve / pipe the file somewhere else
  2. initiate a pipe or a read on the file in it’s new location (ie passed to another function somewhere else, for example trigger a stream upload to a blob storage)
  3. the onEnd callback fires at somepoint.

I’m basically trying to see is there anything that can happen in step 3 that I wouldn’t be able to reasonably handle during step 2 in a different place? If so, it would be nice to figure out a clean way to make a promise implementation here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mcollinacommented, Mar 5, 2020

That will work.

1reaction
Eommcommented, Mar 4, 2020

Oh, I understand.

Who is the streamwriter? Does it implement all the stream lifecycle?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-line Telephone Systems – Kari's Law and RAY BAUM'S ...
The fact that a 911 call has been made;; A valid callback number; and; The information about the caller's location that the MLTS...
Read more >
Plugins - esbuild
All on-end callbacks are run in serial and each callback is given access to the final build result. It can modify the build...
Read more >
Error handling in Node.js - LogRocket Blog
Deliver reliable software by learning how to handle errors in Node.js using callbacks, promises, and event emitters.
Read more >
Observable Finally on Subscribe - Stack Overflow
This way you're not required to always use finalize() : ... #1 Next: 1 #2 Next: 1 #1 Error: error message Finally callback...
Read more >
A Comprehensive Guide To Error Handling In Node.js
Unlike some languages, such as Go and Rust, where you are forced to ... Node.js uses an error-first callback convention in most of...
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