Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6940885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:48:47+00:00 2026-05-27T12:48:47+00:00

So the general convention for callback functions in Node.js is to reserve the first

  • 0

So the general convention for callback functions in Node.js is to “reserve” the first parameter for an error (if one exists). For example:

callSomeBlockingFcn( function callbackWhenDone(err, result) {
  if( err ) ...
});

If you need to return more than one error–say multiple data validation errors, for example–is it considered poor form to pass an array of error objects? Example:

var callSomeBlockingFcn = function(callback) {
  // multiple errors to report back...
  callback( [ err1, err2, ...] );
}

Or is it preferable to avoid arrays and return a single object with a property referencing an array (if necessary)? Example:

var callSomeBlockingFcn = function(callback) {
  // multiple errors to report back...
  callback( { errors: [ err1, err2, ...] } );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:48:48+00:00Added an answer on May 27, 2026 at 12:48 pm

    3 years later:

    Anyone that puts an array in a callback will make me mad.

    The correct solution is to return an error as the first argument. If you want to return multiple errors you are probably using errors for non-exceptional cases.

    In which case it should go in the “value” slot of the callback, i.e. the second argument. The first argument is for a single, unexpected operational error.

    If you have multiple unexpected operational errors (unlikely) you can do something like this MultiError

    Original:

    I think there’s nothing wrong with returning an array of errors.

    Although you could return a new custom ValidationError which has a property "messages" which is an array.

    a)

    function validateX(x, cb) {
      ...
      if (errorMessages) {
        return cb(errorMessages);
      }
    }
    

    b)

    function ValidationError(msgs) {
      this.messages = msgs;
    }
    
    function validateX(x, cb) {
      ...
      if (errorMessages) {
        return cb(new ValidationError(errorMessages));
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a general convention about exposing members in Python classes? I know that
What is the convention for this? Say for example I have the following, where
I'm making a script which has one ajax call inside an each function. The
A lot of my node.js processes are crashing with the ECONNRESET error. Here's the
How to convert a Dictionary to a SortedDictionary? In addition to general conversion (preserving
What are general guidelines on when user-defined implicit conversion could, should, or should not
General Follow the same standards for all tests. Be clear about what each test
General tutorial or good resource on how to use threads in Python? When to
General context : MVVM application. I have a View called JobView. Its DataContext is
General javascript question here, which would also be good to know how(if possible) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.