Record Class DataResult.Error<T>

java.lang.Object
java.lang.Record
com.github.darksoulq.abyssallib.common.serialization.DataResult.Error<T>
Type Parameters:
T - The expected type of the value that failed to resolve.
Record Components:
errorData - The exact runtime failure type evaluated.
path - The cumulative path to the failure point.
All Implemented Interfaces:
DataResult<T>
Enclosing interface:
DataResult<T>

public static record DataResult.Error<T>(DataError errorData, String path) extends Record implements DataResult<T>
The structural implementation of a failed serialization state.
  • Constructor Details

    • Error

      public Error(DataError errorData, String path)
      Creates an instance of a Error record class.
      Parameters:
      errorData - the value for the errorData record component
      path - the value for the path record component
  • Method Details

    • isSuccess

      public boolean isSuccess()
      Specified by:
      isSuccess in interface DataResult<T>
      Returns:
      True if this result represents a success (including partial successes), false otherwise.
    • isError

      public boolean isError()
      Specified by:
      isError in interface DataResult<T>
      Returns:
      True if this result represents an error, false otherwise.
    • isPartial

      public boolean isPartial()
      Specified by:
      isPartial in interface DataResult<T>
      Returns:
      True if this result is successful but carries recorded warnings.
    • result

      public Optional<T> result()
      Specified by:
      result in interface DataResult<T>
      Returns:
      An Optional containing the value if successful, or empty if an error.
    • error

      public Optional<String> error()
      Specified by:
      error in interface DataResult<T>
      Returns:
      An Optional containing the formatted error message if an error, or empty if successful.
    • dataError

      public Optional<DataError> dataError()
      Specified by:
      dataError in interface DataResult<T>
      Returns:
      An Optional containing the exact DataError type evaluated during deserialization.
    • warnings

      public List<DataError> warnings()
      Specified by:
      warnings in interface DataResult<T>
      Returns:
      The collection of recorded warnings if this is a partial result.
    • getOrThrow

      public T getOrThrow()
      Description copied from interface: DataResult
      Retrieves the value or throws a RuntimeException if this is an error.
      Specified by:
      getOrThrow in interface DataResult<T>
      Returns:
      The wrapped value.
    • orElse

      public T orElse(T defaultValue)
      Description copied from interface: DataResult
      Retrieves the value, or returns the provided default value if this is an error.
      Specified by:
      orElse in interface DataResult<T>
      Parameters:
      defaultValue - The fallback value.
      Returns:
      The wrapped value or the default.
    • map

      public <R> DataResult<R> map(Function<? super T, ? extends R> mapper)
      Description copied from interface: DataResult
      Transforms the wrapped value using the provided mapping function.
      Specified by:
      map in interface DataResult<T>
      Type Parameters:
      R - The new value type.
      Parameters:
      mapper - The transformation logic.
      Returns:
      A new DataResult containing the transformed value.
    • flatMap

      public <R> DataResult<R> flatMap(Function<? super T, ? extends DataResult<? extends R>> mapper)
      Description copied from interface: DataResult
      Transforms the wrapped value into a new DataResult using the provided flat-mapping function. Supports covariant return types to prevent generic capture mismatches.
      Specified by:
      flatMap in interface DataResult<T>
      Type Parameters:
      R - The new value type.
      Parameters:
      mapper - The transformation logic that yields a DataResult.
      Returns:
      A new DataResult.
    • mapError

      public DataResult<T> mapError(Function<String,String> errorMapper)
      Description copied from interface: DataResult
      Transforms the error message if this result represents an error.
      Specified by:
      mapError in interface DataResult<T>
      Parameters:
      errorMapper - The logic to apply to the existing error message.
      Returns:
      A new DataResult with the transformed error.
    • prependPath

      public DataResult<T> prependPath(String newPath)
      Description copied from interface: DataResult
      Prepends a path segment to the error context or recorded warnings to build a complete diagnostic trajectory.
      Specified by:
      prependPath in interface DataResult<T>
      Parameters:
      newPath - The path segment to prepend.
      Returns:
      A new DataResult reflecting the updated path logic.
    • addWarning

      public DataResult<T> addWarning(DataError warning)
      Description copied from interface: DataResult
      Injects a recorded warning into the execution timeline without forcing a structural failure.
      Specified by:
      addWarning in interface DataResult<T>
      Parameters:
      warning - The localized diagnostic logging message mapped as an error.
      Returns:
      A modified instance retaining the internal value but flagging warning status.
    • 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.
    • errorData

      public DataError errorData()
      Returns the value of the errorData record component.
      Returns:
      the value of the errorData record component
    • path

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