Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meaningful Errors On Invalid Input? #667

Closed
jamescarr opened this issue Nov 21, 2014 · 6 comments
Closed

Meaningful Errors On Invalid Input? #667

jamescarr opened this issue Nov 21, 2014 · 6 comments
Labels

Comments

@jamescarr
Copy link

Ran across this issue today with some user code on our site:

~  node
> var async = require('async')
undefined
> async.map(process.nosir, function() {}, function() {});
TypeError: Cannot read property 'map' of undefined
    at _map (/home/vagrant/node_modules/async/lib/async.js:54:16)
    at _asyncMap (/home/vagrant/node_modules/async/lib/async.js:237:15)
    at Object.map (/home/vagrant/node_modules/async/lib/async.js:219:23)
    at repl:1:7
    at REPLServer.self.eval (repl.js:110:21)
    at repl.js:249:20
    at REPLServer.self.eval (repl.js:122:7)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)

Is it possible to do some kind of assertion or something at the beginning of the method to ensure that invalid data is not passed in?

@beaugunderson
Copy link
Collaborator

(I'm mostly just helping out with docs, but to clarify:) Would you expect it to still throw an error in the same place but with a more helpful message?

@jamescarr
Copy link
Author

Right. Would expect it to throw an error, just something more meaningful. Something like AssertionError: async.map called with non-array value.

On Fri, Nov 21, 2014 at 5:42 PM, Beau Gunderson [email protected]
wrote:

(I'm mostly just helping out with docs, but to clarify:) Would you expect
it to still throw an error in the same place but with a more helpful
message?


Reply to this email directly or view it on GitHub
#667 (comment).

@aearly
Copy link
Collaborator

aearly commented Nov 23, 2014

Another option would be to treat a null or undefined array as an empty array. Libraries like lodash do this.

@jamescarr
Copy link
Author

👍 I'm more of a fan of being graceful about it to be honest!

On Sat, Nov 22, 2014 at 6:27 PM, Alexander Early [email protected]
wrote:

Another option would be to treat a null or undefined array as an empty
array. Libraries like lodash do this.


Reply to this email directly or view it on GitHub
#667 (comment).

@beaugunderson
Copy link
Collaborator

@jamescarr Just to be clear, are you saying you prefer the lodash approach of treating null/undefined as empty arrays? (And what should happen if you pass in an object?)

@jlg-rayalab
Copy link

Still crashing,

fixed adding this in line 120:
if (typeof arr === "undefined") {
return callback();
}

@aearly aearly added the bug label May 19, 2015
@aearly aearly closed this as completed in 63beb5f Jun 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants