Skip to content

Error object is unwrapped #2

@Animadei

Description

@Animadei

In my development testing I noticed that my try/catch catches a standard Error object that returns a string of the original error object as an Error.message instead of the original Error object. You were trying to preserve the call stack in your code. A problem is that JSON.stringify() actually has a string size limitation so large objects can truncate. Theoretically the Error.message cannot be reconverted back to the original error object thrown and the string conversions are slow. You may have snuck in a non-standard variable into the Error object as "originalError" to try to work around the truncation problem (or for convenience). Would not creating a new AsyncblockError object inherited from the Error class to officially store the original error object technically be what we need instead?

var errorParser = function(self, task) {
    if(task.result && task.result[0] && task.firstArgIsError){
        var err;
        var firstArg = task.result[0];

        if(firstArg instanceof Error){
            //An error object was thrown, just use it
            err = firstArg;
        } else if(typeof firstArg === 'object'){
            //Some sort of object was thrown, convert it into an error object to not lose stack info
            err = new Error(JSON.stringify(firstArg));
            Error.captureStackTrace(err, task.callback);
        } else {
            //Some primitive-ish thing was thrown, convert it into an error object to not lose stack info
            err = new Error(firstArg);
            Error.captureStackTrace(err, task.callback);
        }

        err.originalError = firstArg; <---------

        task.error = err;

        return err;
    }
};

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