Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SuiteScript Error - Catch(e) - e undefined

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?

like image 918
Bud Avatar asked Sep 18 '25 10:09

Bud


2 Answers

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.

like image 166
Steven Deshazer Avatar answered Sep 21 '25 00:09

Steven Deshazer


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/

like image 28
Kinglish Avatar answered Sep 21 '25 01:09

Kinglish