Has anyone ran into this before? In a try catch us...
# suitescript
d
Has anyone ran into this before? In a try catch using JSON.stringify to log the error details is logging an empty JSON object. In this example I force an error and log to error messages. The first one uses the object to log the properties, the second one tries to use stringify. (If it matters this is a map/reduce 2.1 script.)
Copy code
try {
    // force an error
    blah.breakme();
} catch (e) {
    log.error({
        title: `This works as expected`,
        details: {
            message: e.message,
            name: e.name,
            stack: e.stack,
        }
    });
    log.error({
        title: 'This logs an empty JSON object {}',
        details: JSON.stringify(e)
    });
}
b
d
Well that's disappointing but that's exactly it. Thanks!
For others that find this post. If you're looking for functionality similar to 2.0, stringify has a 2nd parameter, replacer, that helps us out.
Copy code
log.error({
    title: 'This logs an empty JSON object {}',
    details: JSON.stringify(ex, Object.getOwnPropertyNames(ex))
});
s
that only captures owned properties. If you have lodash handy (we always do) we use
_.toPlainObject()