Class ExceptionMessages

java.lang.Object
org.apache.gravitino.utils.ExceptionMessages

public final class ExceptionMessages extends Object
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 Details

    • usefulMessage

      @Nullable public static String usefulMessage(@Nullable Throwable throwable)
      Returns a non-blank diagnostic message from throwable or its cause chain.

      Transparent wrappers such as ExecutionException are skipped when selecting candidate messages. Among remaining frames, the shallowest non-blank message is preferred so nested wrap(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

      public static String withCause(String context, @Nullable Throwable throwable)
      Combines operation context with the underlying cause message.

      If context already contains the useful cause message, context is returned unchanged. If there is no useful cause message, context is 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

      public static RuntimeException wrap(String context, Throwable throwable)
      Wraps throwable in a RuntimeException whose message includes both context and the underlying cause message.
      Parameters:
      context - operation/object context
      throwable - the underlying failure
      Returns:
      a runtime exception suitable for rethrowing from catalog operations
    • illegalArgument

      public static IllegalArgumentException illegalArgument(String context, Throwable throwable)
      Creates an IllegalArgumentException whose message includes both context and the underlying cause message.
      Parameters:
      context - operation/object context
      throwable - the underlying failure
      Returns:
      an illegal-argument exception for client-caused failures