1

Most of my code is error handled with try/catch and OpenLog (modified to handle SSJS exceptions). Unfortunately, exception in SSJS gives hard to read stack trace.

So I need to pass more info - at least event/method where is the error handler. I can simply put "method XY" argument to every OpenLog.logError call, but this makes every handler unique and prone to errors (programmers love copypasta). It would be nice to have LSI_Info equivalent, what makes error handlers constant (so you can define them as template in Eclipse).

Is there any call, which returns "where I am" info of method/event for SSJS code (including libraries)?

Community
  • 1
  • 1
Frantisek Kossuth
  • 3,524
  • 2
  • 23
  • 42
  • Off topic: Just to warn people. Do not use LSI_INFO() any more. It can cause memory corruption/crashes. Correct LS command is GetThreadInfo(). http://www-01.ibm.com/support/docview.wss?uid=swg21237286 – Simon O'Doherty Feb 21 '13 at 13:51
  • Xpages logs in IBM_TECHNICAL_SUPPORT folder normally detail the XPage and line of code that is failing. – Simon O'Doherty Feb 21 '13 at 13:53
  • 1
    Here are some ideas http://dontpanic82.blogspot.fi/2009/12/helper-functions-for-debugging-xpages.html but I'm not sure if you can get the method/event this way. – Panu Haaramo Feb 21 '13 at 14:02
  • @SimonO'Doherty: I am aware of IBM_TECHNICAL_SUPPORT logs. You will see only unhandled exceptions there (Error 500 shown to user). Error 500 can be avoided by try/catch with @ErrorMessage() (and openlog where necessary), what is more friendly to users. – Frantisek Kossuth Feb 21 '13 at 14:04
  • 7
    The only decent way to determine function stack in JavaScript (arguments.callee.caller) was removed from the spec and is therefore not supported in SSJS. Google abounds with workarounds, most (if not all) of which would be a nightmare to port to SSJS. I know most XPage developers don't want to be told to "just use Java", but if you prefer robust error management, use a language that natively contains it... in other words, just use Java. – Tim Tripcony Feb 21 '13 at 14:52

1 Answers1

6

Have a look at the code in the Message class of my debug toolbar (found here on GitHub). I contains a way to 'pretty print' errors and also captures a com.ibm.jscript.InterpretException. I use that to send a formatted error message to an OpenLog event document. It (sort of) mimics the information you get in the default XPage error page.

To see what the formatted error looks like go to my toolbar's demo page and hit the Test 1 or Test 2 button. That will throw a SSJS error that is captured by a custom error form. That form writes a message to the toolbar which is configured to also store error messages in a separate OpenLog database.

(toolbar download can be found here on OpenNTF)

Mark Leusink
  • 3,747
  • 15
  • 23