You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@druid.apache.org by Roman Leventov <le...@apache.org> on 2019/05/13 11:23:51 UTC

Throwables.getRootCause()

Please use Throwables.getRootCause() as a robust way to get
e.getCause().getCause()... until null is encountered. I think this is
especially true in REST, where we should say

serverError().entity(ImmutableMap.of("error", Throwables.getRootCause(e)))

To provide the caller with the actual reason of the error (for example,
some I/O errors sometimes have long cause chains with something like "no
disk space left on device" in the end).

(Side note: somebody may want to inspect the security of this practice, but
currently the code is not considered with security implications of
reporting errors to REST callers at all, as far as I can say.)

(Second side note: for logging, it's probably better to not to unwind the
cause, to provide cluster operators and developers with the full stack.
However, there are some places of log.error("...", e.getCause()) in the
codebase, which should probably be replaced with just log.error("...", e).)

There are also some places in the codebase with code like (e.getCause() ==
null ? e : e.getCause()) (just search "getCause" in the codebase) which
should probably better be replaced with Throwables.getRootCause().