I have a simple try/catch block in my SuiteScript:
try
{
var csvFile = file.create({name : outputFileName,
contents : header,
folder : 123,
fileType : 'xy'});
}
catch (e)
{
log.debug({
title : 'Error',
details : e.description
});
}
(note that in the above the fileType of 'xy' is intentional, to force the error).
The problem is that when I get to the catch block, 'e' is always undefined. That's how it's logged and that's what the debugger shows. I don't know how that can even happen.
What could be causing this?
Could it be that e
is defined but e.description
is not? Netsuite uses e.name
and e.message
for their custom SuiteScriptError objects (not e.description
). These can be logged by using dot notation or just with JSON.stringify(e)
. If it is just a JavaScript Error object (triggered by a syntax error for example), then JSON.stringify
won't work, but you can still use e.name
and e.message
.
This may or may not be a solution for you, but there is a free set of SuiteScript abstractions specifically geared for more helpful error catching: https://github.com/datatek-software/netsuite-patterns
Your code would become:
const fobj = {
name : outputFileName,
contents : header,
folder : 123,
fileType : 'xy'
}
const create = safeExecute(file.create, fobj);
if (!create.isSuccess) {
console.error(create.message);
console.warning(create.stack);
}
If the call is unsuccessful, the isSuccess property will be false and the message property will contain the message exception. If you need it, the stack property will contain the stack trace for the exception.
More: https://datatek.io/2019/04/25/suitescript-with-a-safety-net/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With