Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error object is unwrapped #2

Open
Animadei opened this issue Jul 24, 2016 · 0 comments
Open

Error object is unwrapped #2

Animadei opened this issue Jul 24, 2016 · 0 comments

Comments

@Animadei
Copy link

Animadei commented Jul 24, 2016

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;
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant