Record Class Diagnostic

java.lang.Object
java.lang.Record
com.ultikits.ultitools.exceptions.Diagnostic
Record Components:
code - the error code for this occurrence
whatHappened - the caller's description of the failure, including the concrete subjects (such as the affected class and field) when applicable

@Internal public record Diagnostic(ErrorCode code, String whatHappened) extends Record
Formats an occurrence of an error as a description, a repair, and a documentation reference. Exception messages are retained verbatim; repeated guidance is removed only when displayed.
  • Field Details

  • Constructor Details

    • Diagnostic

      public Diagnostic(ErrorCode code, String whatHappened)
      Creates an instance of a Diagnostic record class.
      Parameters:
      code - the value for the code record component
      whatHappened - the value for the whatHappened record component
  • Method Details

    • fromCause

      public static Diagnostic fromCause(ErrorCode fallback, String whatHappened, Throwable cause)
      Selects a specific framework code through exception wrappers, including reflective invocation.
    • forPostConstruct

      public static Diagnostic forPostConstruct(String beanName, Class<?> declaringClass, String method, Throwable cause)
      Names the failing lifecycle callback independently of the code selected from its cause.
    • asContainerException

      public ContainerException asContainerException(Throwable cause)
      Creates the existing typed exception without changing its cause chain.
    • prefix

      static String prefix(ErrorCode code)
    • render

      public String render()
      Renders this occurrence with the documentation page's location inside the UltiTools-API JAR.
      Returns:
      the three-part diagnostic
    • headline

      public String headline()
      Renders this occurrence without its fix and documentation lines.
    • log

      public void log(Logger logger, Level level, Throwable failure)
      Logs the selected guidance exactly once. If a cause already carries the selected code's guidance, the record adds only context. Other rendered causes retain their text and frames but not a second fix or documentation link. No exception received by callers is rewritten.
    • lastCompactFrame

      private static int lastCompactFrame(List<Diagnostic.LogFrame> frames, int owner)
    • projectLogPrefix

      private static Throwable projectLogPrefix(List<Diagnostic.LogFrame> frames, int owner, int lastCompact, @Nullable @Nullable Throwable tail)
    • originalFailure

      public static Throwable originalFailure(Throwable failure)
      Returns the original exception for consumers that use the exception's type and identity.
    • compactStackHeading

      public static String compactStackHeading(Throwable failure)
      Formats a stack heading after the surrounding report has already included the guidance.
    • failureName

      private static String failureName(Throwable failure)
    • descriptionOf

      @Nullable public static @Nullable String descriptionOf(Throwable failure)
      Returns the occurrence text, without embedding the fix and reference in another heading.
    • fromFailure

      public static Diagnostic fromFailure(ErrorCode fallback, String context, Throwable failure)
      Adds context to a failure without repeating the cause's fix and documentation lines.
    • findIn

      public static Optional<Diagnostic> findIn(Throwable failure, ErrorCode directClassMissCode)
      Recognises a coded cause, but gives a failed direct class lookup the caller's code. A linkage failure for a referenced class keeps its dependency code instead.
    • findIn

      public static Optional<Diagnostic> findIn(@Nullable @Nullable Throwable failure)
      Looks through wrappers for a more specific failure. Framework exceptions carry their code explicitly. The bootstrap and class-loader boundaries must keep their exact JDK exception types, so there we recognise only a complete diagnostic, not a code mentioned in prose.
    • readRendered

      @Nullable public static @Nullable Diagnostic readRendered(@Nullable @Nullable String message)
      Recognizes only a complete diagnostic, not a code or a guidance label mentioned in prose.
    • unwrapInvocation

      private static Throwable unwrapInvocation(Throwable failure)
    • causeOf

      @Nullable private static @Nullable Throwable causeOf(Throwable failure)
    • describe

      private static String describe(Throwable failure)
    • messageOf

      @Nullable private static @Nullable String messageOf(Throwable failure)
    • guidance

      private static String guidance(ErrorCode error)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • code

      public ErrorCode code()
      Returns the value of the code record component.
      Returns:
      the value of the code record component
    • whatHappened

      public String whatHappened()
      Returns the value of the whatHappened record component.
      Returns:
      the value of the whatHappened record component