Question: Why do we need cb(null, '...') ?
See original GitHub issueHello 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:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
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.
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; hencecb(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! 👍
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.