+1

The callback should always be invoked exactly once. So either you call it 
when you get the first error, or you call it at the end with an error 
object that encapsulates all the errors.

Whether you want to stop at the first error, or gather all of them is 
another story. In most cases, your function has a simple contract like "do 
xyz" and it won't be able to fullfil it as soon as it hits one error. So it 
is better to stop right away but there are situations where your function 
has a more sophisticated "contract" like "do xyz or tell me all the things 
I have to fix to be able to do xyz" (typical case is a compiler: compile or 
give me all the errors). In this case it is better to run to the end and 
gather all errors.

Bruno

On Friday, July 6, 2012 11:04:23 AM UTC+2, Mariusz Nowak wrote:
>
> You definitely should report with one error object, and you won't find 
> function in Node.js API that returns more than one error.
>
> Most straightforward way would be to fail your function as soon as first 
> error occurs, and report with that error. However if you'd like to have 
> more complete solution, that tries to delete all files and collects error 
> information on the way, then you may want to report all approached errors 
> on one error object. You can do it either via error.message or via other 
> custom property on error object.
>
>
> On Thursday, July 5, 2012 5:44:45 PM UTC+2, Alan Gutierrez wrote:
>>
>> Let's say that somewhere within your library, you delete the contents of 
>> a 
>> directory in parallel. Let's say all the files in a  directory are 
>> read-only so 
>> all your parallel requests return an error. 
>>
>> If you've exposed a Node.js style asynchronous function with an `(error, 
>> result, 
>> result...)` callback, how do you report multiple errors to person who 
>> called 
>> your library? Do you wrap the multiple errors in a single error, maybe 
>> having an 
>> array of `causes`? Do you note that multiple errors may be returned? 
>>
>> Are the functions in the Node.js API that might return more than one 
>> error that 
>> I could study? Do any of the event emitters in the Node.js API emit a 
>> series of 
>> errors, or is it just one error prior to entering an error state? 
>>
>> -- 
>> Alan Gutierrez - http://twitter.com/bigeasy - http://github.com/bigeasy 
>>
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to