Result

value class Result<out T, out E>(unboxed: Any?)

Success value T or typed error E, distinct from kotlin.Result.

Callback exceptions propagate unchanged; this wrapper does not catch transport exceptions. Use fold to handle both branches or getOrThrow when a typed error should abort the operation. A successful result containing a Flow does not guarantee that collecting that flow will succeed. Error values and this result's string representation can contain raw daemon data; do not expose them as safe diagnostics. Use dockerContext on SDK exceptions for sanitized operation metadata.

Samples

docker.containers.getInfo(id).fold(
    onSuccess = { container -> println(container.state) },
    onError = { failure -> println("Docker rejected inspect: ${failure.message}") },
)

Constructors

Link copied to clipboard
constructor(unboxed: Any?)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Failure(val error: Any?)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun errorOrNull(): E?

Returns the typed error, or null on success. A nullable error can also be null.

Link copied to clipboard
inline fun <R> fold(onSuccess: (T) -> R, onError: (E) -> R): R

Invokes exactly one branch and returns its value. Callback exceptions propagate.

Link copied to clipboard
fun getOrNull(): T?

Returns the success value, or null on error. A successful nullable value can also be null.

Link copied to clipboard
fun getOrThrow(): T

Returns the success value, or throws for a typed error.

Link copied to clipboard
inline fun <R> map(transform: (T) -> R): Result<R, E>

Transforms the success value, preserving errors and their operation context/cause unchanged. Transform exceptions propagate.

Link copied to clipboard
inline fun <R> mapError(transform: (E) -> R): Result<T, R>

Transforms the error value, preserving success unchanged and retaining SDK operation context/cause. The retained cause describes the original failure, not the transformed error. Transform exceptions propagate.

Link copied to clipboard
inline fun onError(action: (E) -> Unit): Result<T, E>

Runs action only on error and returns this result unchanged. Action exceptions propagate.

Link copied to clipboard
inline fun onSuccess(action: (T) -> Unit): Result<T, E>

Runs action only on success and returns this result unchanged. Action exceptions propagate.

Link copied to clipboard
open override fun toString(): String