Package org.apache.gravitino.utils
Class ExceptionMessages
java.lang.Object
org.apache.gravitino.utils.ExceptionMessages
Helpers for preserving underlying system error messages when wrapping exceptions.
Catalog and server code often adds operation context when rethrowing. Context is useful, but it must not replace the upstream message that operators need to act on.
-
Method Summary
Modifier and TypeMethodDescriptionstatic IllegalArgumentExceptionillegalArgument(String context, Throwable throwable) Creates anIllegalArgumentExceptionwhose message includes bothcontextand the underlying cause message.static StringusefulMessage(Throwable throwable) Returns a non-blank diagnostic message fromthrowableor its cause chain.static StringCombines operation context with the underlying cause message.static RuntimeExceptionWrapsthrowablein aRuntimeExceptionwhose message includes bothcontextand the underlying cause message.
-
Method Details
-
usefulMessage
Returns a non-blank diagnostic message fromthrowableor its cause chain.Transparent wrappers such as
ExecutionExceptionare skipped when selecting candidate messages. Among remaining frames, the shallowest non-blank message is preferred so nestedwrap(String, Throwable)/withCause(String, Throwable)context is not discarded. When a deeper non-blank reason is not already contained in that message, it is appended.- Parameters:
throwable- the throwable to inspect, may be null- Returns:
- a useful message, or null if none is available
-
withCause
Combines operation context with the underlying cause message.If
contextalready contains the useful cause message,contextis returned unchanged. If there is no useful cause message,contextis returned as-is.- Parameters:
context- operation/object context such as"Failed to alter topic X"throwable- the underlying failure- Returns:
- a message that preserves both context and the upstream reason when available
-
wrap
Wrapsthrowablein aRuntimeExceptionwhose message includes bothcontextand the underlying cause message.- Parameters:
context- operation/object contextthrowable- the underlying failure- Returns:
- a runtime exception suitable for rethrowing from catalog operations
-
illegalArgument
Creates anIllegalArgumentExceptionwhose message includes bothcontextand the underlying cause message.- Parameters:
context- operation/object contextthrowable- the underlying failure- Returns:
- an illegal-argument exception for client-caused failures
-