UI5 / UI5/openui5

Enhancement to Logger (handle Error's in a more supportive way)

Open
#2,278 5 comments 1 reaction 1 assignee View on GitHub

@flovogt is already working on this.

Since Feb 11, 2025.

enhancement in progress
Dominant language
JavaScript
Stars
3.3k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

OpenUI5 version:
all

Browser/version (+device/version):
n/a

Any other tested browsers/devices(OK/FAIL):
n/a

We're trying to use the jQuery.sap.log.* code (or the new sap.base.Log), which, for the most part, this works very well. But we have discovered that when an exception occurs, a Javascript error (maybe something undefined), only the message is captured by the logger.

Since all errors logged, are automatically sent to console.error, its understandable that the developer trusts the automatically included stacktrace. But this stacktrace is now wrong.
When you know this, its just annoying and unhelpful. If you don't know it, time and hair is lost.

For me the core issue is where the error is forced to be a string:
message : String(sMessage || ""),
The object passed in, with its (valuable) stack trace, is lost.

If oLogEntry could include the original "message" (which could be an object), even if the logger code only wants a string, all listeners have a fighting chance to handle this differently.

Might not seem like much, but try changing all console.error messages in your code base to logger.error() and try tracking down an exception - you can't find the source of the issue in webtools any more, because the stacktrace is not the stacktrace you think it is.

This issue really becomes much worse when you throw promises into the mix. A common problem with promises is they often "catch" more than they should. E.g. A model update (using ajax) where many listeners are observing the model changes, catches an exception. However, the exception occurred in some utility class, indirectly referenced by one of the listeners! Without stack traces, it takes some time before you realise the model update code is perfect, the issue is in an entirely different place.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.