enonic / doc-xp

Enonic XP > 7.0 Reference Documentation
2 stars 4 forks source link

try catch error log stacktrace and continue #168

Open ComLock opened 4 years ago

ComLock commented 4 years ago

Currently I know of no way to log a stacktrace and continue. Please document how, or make it possible ? :)

Related: https://discuss.enonic.com/t/catch-specific-java-errors-in-javascript/928/3

alansemenov commented 4 years ago

@rymsha any suggestions? has to be implemented?

rymsha commented 4 years ago

This is a documentation issue. https://github.com/enonic/doc-xp/blob/master/docs/framework/globals.adoc#log

The trick is to provide two arguments where second one is an exception instance:

try {
  bean.run();
} catch (e) {
   log.info('Red Alert!', e)
}

@anatol-sialitski document it, please, since you implemented this improvement.

ComLock commented 4 years ago

So you're saying that if I do:

log.debug(e); There's no stacktrace in the log

But if I do log.debug('', e); Then I get the stacktrace?

anatol-sialitski commented 4 years ago

Yes, by the idea you should be able to log stacktrace if second parameter will be passed as an error/exception.

ComLock commented 4 years ago

What if I want to store the stacktrace in a variable and write it to a Enonic XP node so I can debug errors later? Still sure this is a documentation issue?

sigdestad commented 4 years ago

You should never store error stack-traces in XP (imagine what might happen), if you intend to store them anywhere, write them to logs.