Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'replace' of undefined #3

Open
mark05e opened this issue Mar 24, 2022 · 1 comment
Open

TypeError: Cannot read property 'replace' of undefined #3

mark05e opened this issue Mar 24, 2022 · 1 comment

Comments

@mark05e
Copy link

mark05e commented Mar 24, 2022

I tried to import the BBLog.gs file alone as a library and try to execute a test function - I get an error inside the console

The function I used to test is

function myFunction() {
  var lock = LockService.getScriptLock();
  var log = BBLog.getLog({
    level: BBLog.Level.ALL,  
    sheetName: 'Log',
    displayFunctionNames: BBLog.DisplayFunctionNames.YES,
    displayUserId: BBLog.DisplayUserId.EMAIL_FULL,
    lock: lock
  });
  log.info('Test log to GSheet at INFO level');
}

The error inside the console

TypeError: Cannot read property 'replace' of undefined
BBLog_._getFunctionName                @ BBLog.gs:908
convertUsingDefaultPatternLayout       @ BBLog.gs:871
BBLog_._log                            @ BBLog.gs:780
BBLog_.info                            @ BBLog.gs:331

and I get this log line inserted on the sheet

2022-03-24 09:42:36:600 -0400 000383 mark@XXXXX.com INFO     at BBLog_.info (BBLog:331:8) Test log to GSheet at INFO level

In another scenario, when I add the library directly to the sheet and run a modified test function...

function myFunction() {
  var lock = LockService.getScriptLock();
  var log = getLog({
    level: Level.ALL,  
    sheetName: 'Log',
    displayFunctionNames: DisplayFunctionNames.YES,
    displayUserId: DisplayUserId.EMAIL_FULL,
    lock: lock
  });
  log.info('Test log to GSheet at INFO level');
}

I get this output on the console

2022-03-24 10:15:33:363 -0400 000881 mark@XXXXX.com INFO     at myFunction (Tests:11:7) Test log to GSheet at INFO level

and this line on the sheet

2022-03-24 10:15:32:819 -0400 000337 mark@XXXXX.com INFO     at BBLog_.info (BBLog:331:8) Test log to GSheet at INFO level

I am wondering if this is because the configuration of depreciated runtime you have on your appsscript.json file?

  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "DEPRECATED_ES5"
@andrewroberts
Copy link
Owner

It does look like you've found an issue with running it on V8. It is because DisplayFunctionNames is set to YES.

It has never been possible to have this set to YES and run the debugger, as BBLog throws and catches an error to get the function name, which stops the debugger running. But with V8 it looks like DisplayFunctionNames will not work running as normal or with the debugger.

Thanks for flagging this up. The DisplayFunctionNames was always a nasty gotcha that used to catch me out occasionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants