Casebook05 · SuiteScript

The catch block that logs at Debug

Errors are caught and logged at Debug level, which production accounts usually hide. The record saves with missing data and nobody is told.

  • Casebook 05
  • SuiteScript

What you notice

Some records end up with blank fields that a script should have filled. The execution log shows nothing wrong.

Why it happens

The script wraps its work in try/catch and logs the error with nlapiLogExecution('DEBUG', ...), or does nothing in the catch at all. Production deployments usually log at Audit or Error, so Debug lines never appear. The save carries on without the data.

The fix in 2.1

Log at Error, with the record ID and message, so the problem shows up. When bad data must not be saved, throw a named error from beforeSubmit so the user sees it.

const beforeSubmit = (context) => {
  try {
    validate(context.newRecord);
  } catch (e) {
    log.error({ title: 'Validation failed', details: { id: context.newRecord.id, message: e.message } });
    throw error.create({ name: 'VALIDATION_FAILED', message: e.message });
  }
};

For background jobs, review failures in the Map/Reduce summarize stage and send one alert, instead of hoping someone reads the log.

What to check in your account

Search for catch blocks that are empty or only log at DEBUG, and check the log level on each production deployment.

Back to the casebook