5

My question is mighty simple: how do you get the error message!?

All I have to go off of is the red box at the top that says "Script CustomSort Experienced an Error," which is almost as vague as one can get!

Going deeper, the following worked about a week ago, now it no longer does. I haven't touched the script for at least a month. Rows have been added though. I reverted my spreadsheet back to a state when it used to work, but it still does not work.

function onOpen() 
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ {name: "Custom Sort", functionName: "CustomSort"}];
  ss.addMenu("Sort", menuEntries);

  CustomSort();
}

function CustomSort() 
{
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange(2,1,sheet.getMaxRows()-1,sheet.getMaxColumns()); 

  var headers = sheet.getRange(1, 1, 1, sheet.getMaxColumns()).getValues();
  var sortOrder = new Array;
  sortOrder.push({ column: headers[0].indexOf("Completion Date")+1, ascending: true });
  sortOrder.push(headers[0].indexOf("Owner")+1);
  sortOrder.push(headers[0].indexOf("Tentative Due Date")+1);
  sortOrder.push({ column: headers[0].indexOf("Priority")+1, ascending: false });
  sortOrder.push(headers[0].indexOf("Department")+1);

  range.sort(sortOrder); 
}

I can run the script within the script editor with no errors, but my understanding is that it runs the script with an empty sheet (is that true?), which may signal there is an issue within the sheet.

With an error or even a line number, I'd figure it out in a jiffy! I am trying to avoid ripping apart the rather large spreadsheet or code to figure this out.

I have done a bunch of Googling, and there are many references to similar issues being a Google problem, but I think this issue has existed for several days.

(I have also had no luck with logging ever, which further restricts my ability to debug. In short, I feel like I'm handicapped in the debugging tools department. My only strategy is to reduce everything down to the simplest test case and slowly adding line of code or row of spreadsheet at at time until it blows up. Surely there has to be a better way; oh great internet, please give me your wisdom!)

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Zoop
  • 965
  • 1
  • 13
  • 24
  • Well, I got it to work... by simply commenting all the code, saving, reloading, and then removing all the comment-outs, saving, and reloading. Thus, no change to the code, but now it works? Weird... – Zoop Sep 04 '13 at 04:32
  • Still doesn't answer my question of: how do I find the error message/line? – Zoop Sep 04 '13 at 04:32

3 Answers3

3

Hmm, how about good 'ol try-catch +e-mail or logger to get at least hint on error and than debug watching carefully data in debugger (breakpoint at suspected line, review state of data, step by step debug):

function calculateSmthng()
{
  try {
       makeHardWorkForMe();
      } 
  catch (e) {
      MailApp.sendEmail("me@example.com", "Error report from ...", e.message); //either with e-mail
      Logger.log("Bad thing happened, catched at calculateSmthng(): " +e.message); //or logger
     }
}

It usually did the trick for me.

PsychoFish
  • 1,541
  • 12
  • 11
0

When you have a failure like this, check the Execution Transcript, under the "View" menu item. It typically shows the results of the last execution of the script, and will indicate the last-run line.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 1
    I definitely checked there at the time (cannot confirm now), and it did not show anything. Several times I've checked there, and the only time it contains any information is if I debug it within the code editor. – Zoop Sep 12 '13 at 19:39
  • 1
    I'd upvote (because others may not know that), but my account is too noob to do so. – Zoop Sep 12 '13 at 19:40
  • The Execution Transcript doesn't have any information if the script is not executed, which is my case. – gciriani May 10 '19 at 15:43
0

I know this is an old post, but for the case of others finding it. I got this error because I failed to put the function name in quotes!

Had this (note mapExport):

function onOpen() {
  var sheet   = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{name:'Update Map Export', functionName: mapExport}];
  sheet.addMenu("Build Export", entries);
};

Instead of this:

function onOpen() {
  var sheet   = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{name:'Update Map Export', functionName: 'mapExport'}];
  sheet.addMenu("Build Export", entries);
};
kgingeri
  • 111
  • 1
  • 9