Randy
Randy

Reputation: 3

How can I get real time script error notification when using a google sheets onOpen() function that errors out?

I can see the 'failure' and 'paused' errors when I view stackdrive-logging. I would like a notification, similar to a Browser.msgBox() when any error occurs in the script, so that i can then check the stackdriver-logger for details. I do not need any details, just a simple pop-up notification while working in the spread sheet. I looked at adding a Trigger, but can not making sense of how to implement an [on-ERROR].

Upvotes: 0

Views: 276

Answers (1)

Suppose you have onOpen function code such as below:

function onOpen(e) {
  var x = 1 / y; // initial code with possible error
}

We can and should handle possible errors by try .. catch block. Error object e1 contains useful error description, you might want to display it as alert. So the code should be like this one:

function onOpen(e) {
  try {
    var x = 1 / y; // initial code with possible error
  } catch(e1) {
    SpreadsheetApp.getUi().alert(e1.message);
  } 
}

Really it shows alert box with error description after spreadsheet open.

Upvotes: 1

Related Questions