Error Object Properties
SuiteScript supports the ECMAScript Error object to represent errors that can occur in scripts. You can call JSON.stringify(obj) on an Error object to obtain a string representation of the error. If you pass an argument to the Error object constructor, the string representation in SuiteScript 2.0 includes the argument as the value of the message property. The string representation in SuiteScript 2.1 does not include the message property.
This difference is because of how JSON.stringify(obj) handles enumerable and non-enumerable properties. In SuiteScript 2.0, the output of JSON.stringify(obj) includes the content of both enumerable and non-enumerable properties. In SuiteScript 2.1, the output of JSON.stringify(obj) includes only the content of enumerable properties and does not include the content of non-enumerable properties, as per the ECMAScript specification.
When you pass an argument to the Error object constructor, a non-enumerable message property is defined. If you change the value of this property after the Error object is created, the property remains non-enumerable. So, when an Error object is created with an argument, the message property is not included in the JSON.stringify(obj) output in SuiteScript 2.1 scripts.
By contrast, when you do not pass an argument to the Error object constructor, the message property is not defined. If you try to set the value of this property after the Error object is created, a new message property is defined. Properties that are defined in this way are always enumerable. So, when an Error object is created without arguments, the message property is included in the JSON.stringify(obj) output in SuiteScript 2.1 scripts.
|
Scenario |
SuiteScript 2.0 Behavior |
SuiteScript 2.1 Behavior |
|---|---|---|
|
Create an Error object without an argument in a script:
|
The
|
The
|
|
Create an Error object with an argument in a script:
|
The
|
The
|
To avoid this issue, use only enumerable properties for objects. For error messages, create Error objects with no arguments. For more information, see JSON.stringify(obj) and Enumerability and ownership of properties.