Skip to content

Error Codes #206

Closed
Closed

Description

@jogly

This may be a sizable undertaking, but I think should be considered. I've come across a situation in which one particular error of a few that may be returned by ORM is OK. However, the only way to identify that error is by the string message. There should be some other more stable identifying piece of information such as an error code, in addition to the messages.

Activity

  1. dresende commented on Jun 22, 2013

    @dresende
    Owner

    Can you show me an example of such error?

  2. jogly commented on Jun 23, 2013

    @jogly
    CollaboratorAuthor

    Gladly :)

    For example, the Model function get(id, callback) can throw a few errors, some of which are, missing callback; key length mismatches; or, my allowable error, a not found error. The only identifiable information available is the "Not found" string in the error object. One solution is to extend the error object into a generic ORM error object that will contain the message and a code.

    var ORMError = function(msg, code[, constr]) {
        Error.captureStackTrace(this, constr || ORMError);
        this.message = msg;
        this.code = code;
    };
    
    util.inherits(ORMError, Error);

    Now, we can use throw new ORMError("Same message", NEW_CODE);, or create reusable errors:

    var NotFoundError = function(msg) {
        this.super_.call(this, msg, SOME_CODE, this.constructor);
    };
    
    util.inherits(NotFoundError, ORMError);

    This is something that could be phased in without affecting any existing code since every custom error will already effectively be an error.

  3. dresende commented on Jun 24, 2013

    @dresende
    Owner

    Ok, I clearly see your point. You would like to have a way of distinguishing the errors without parsing a string (that might change). We have to identify them and create codes for them, perhaps having a global orm file with the list of codes (that people can lookup) and orm will use. I have to create a basic one, perhaps starting with the Model.get.

  4. dresende commented on Jun 27, 2013

    @dresende
    Owner

    There should be more missing errors there, I have to change all of them. If you find any, feel free to change it.

  5. dresende commented on Jun 27, 2013

    @dresende
    Owner

    I think I added most of them. If you find any please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions