cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

when.spread throws TypeError if argument is non-array #481

Open ChrisEineke opened 8 years ago

ChrisEineke commented 8 years ago
when(null).spread();
when(undefined).spread();

leads to a TypeError "Cannot read property 'length' of null", whereas

when(1).spread();

leads to a TypeError "cannot call method 'apply' of undefined".

The errors are a little obtuse. They should indicate that when.spread expects an array when non-array given.

briancavalier commented 8 years ago

Hi @ceineke, sorry for the confusing error. It should be easy enough to check and provide a more helpful message.

ChrisEineke commented 8 years ago

I'll be happy to provide a pull request. Do you have your own error class or would you throw Error?

briancavalier commented 8 years ago

A PR would be awesome, thank you. TypeError actually seems like the right thing to me in this case, so maybe start there and we can see how we feel about it once the PR is up. Sound good?