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.

Question: Why do we need cb(null, '...') ?

See original GitHub issue

Hello together,

I had a few weeks now with the new Multer Release/API and it works well for me so far. Thanks for optimizing it and making it better.

Just one thing in the new API feels a bit strange to me when using (f.e.) the disk storage .

cb(null, '/tmp/my-uploads') 

It confuses me a bit to explicitly pass a null value. Is it important here? Can’t we make that parameter just optional? We could somehow still throw / pass an Error if something goes wrong. Do we have control over it, or does it maybe relate to the “next()” express middleware call?

At least I would expect a small hint in the documentation what this null value is all about. When I used the disk storage for the first time, I was a bit confused about this. Later on in the documentation I found

cb(new Error('I don\'t have a clue!'))

and things were a bit more clear for me, but it’s still a different part in the documentation

Regards Rolf

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
LinusUcommented, Aug 10, 2015

This is a very fundamental part of Node.js and it’s part of every function in the standard api. You are probably used to seeing the other side of it thought.

Consider the following example for reading a file.

fs.readFile('/tmp/linus.txt', function (err, raw) {
  if (err) throw err

  console.log('File contains:', raw.toString())
})

err is always the first parameter of a callback, indicating if an error occurred or not. Since you are now implementing the other side, you’ll be the one that actually supplies the error and the result; hence cb(null, 'result').

I really recommend reading Error Handling in Node.js, it should tell you all about this.

Personally I don’t think that we need to document this further since it’s such a fundamental part of Node.js. Please tell me if you think I’m wrong thought! 👍

1reaction
ryhincheycommented, Mar 6, 2020

I’m going to go ahead and close this issue. @darmawan01 & @4dams feel free to open new issues with your specific problems if you’re still facing them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the null argument to cb in multer? - Stack Overflow
The null means there was no error and you are calling the callback with a successful completion and a resulting ...
Read more >
Prove that if Ax=0 and Bx=0 iff A=CB? [closed]
I want to prove that null(A) is the same as null(B) if and only if there exists an invertible matrix C such that...
Read more >
Solved QUESTION 6 If we do not reject the null hypothesis
CB. O There is enough statistical evidence to infer that the null hypothesis is true he test is statistically insignificant at whatever level...
Read more >
Hypothesis Testing - its.caltech.edu
In hypothesis testing, you are interested in testing between two mutually exclusive hy- potheses, called the null hypothesis (denoted H0) and the ...
Read more >
SAT Practice Test #8 Answer Explanations
Have we not always had quarrels and difficulties over it? And when will we cease to have quarrels over it?” These questions imply...
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