Reputation: 11
I just divided my 1800 line project into 12 'Files' within the Spreadsheet Script Editor. I noticed that the Find function only looks within the active File.
Is there anyway to do a global find ?
Also related to Files within a Project, when errors are thrown, a line number is referenced but not the File name.
Is there a way to determine which File contains the line that caused the error ?
Thanks Dan
Upvotes: 1
Views: 170
Reputation: 17792
To determine the file that caused the error you have to try-catch the error and parse the stacktrace. Here is what I do:
function yourCallingfunction() {
try {
//do your thing
} catch(err) {
stack = parseErr_(err)
Logger.log(stack);
throw stack;
}
}
//Try to parse errors stacktrace into a nicer format
function parseErr_(e) {
var ret;
if( e !== undefined && e !== null && e.stack ) {
ret = e.name +': '+e.message+' \nStacktrace: \n';
var stack = e.stack.replace(/\n/g,'').match(/:\d+( \([^\)]+\))?/g);
for( var i in stack )
ret += stack[i].replace(/[\(\):]/g,'').split(/ /).reverse().join(':') + ' \n';
} else
ret = e;
return ret;
}
About the global find, if your issue is only find, not replace, there's a workaround too. Take a look at this:
function showMe() {
for( var i in this )
Logger.log(this[i].toString());
}
But non of this are actual solutions. You should star the issues linked by @ScampMichael
Upvotes: 2
Reputation: 3728
There is no way to do a global find. Find will only look in the current file. I agree that there should be a find and replace that would transverse the entire project and I filed and issue back in September 2011, in the Issue Tracker at:
http://code.google.com/p/google-apps-script-issues/issues/detail?id=822
Please go there and star it to vote it up and be notified of any progress on this issue.
The issue of no file name being reported with error messages has also been raised in the Issue Tracker at:
http://code.google.com/p/google-apps-script-issues/issues/detail?id=747
Upvotes: 2