OperationResult Class

Represents the result of an operation.

This class encapsulates the success or failure state of an operation along with any associated errors.

Initialize a new instance of the OperationResult class.

Constructor

OperationResult(succeeded: bool, errors: List[OperationError] | None = None)

Parameters

Name Description
succeeded
Required

Flag indicating whether the operation succeeded.

errors

Optional list of errors that occurred during the operation.

Default value: None

Methods

failed

Create an OperationResult indicating a failed operation.

success

Return an OperationResult indicating a successful operation.

failed

Create an OperationResult indicating a failed operation.

static failed(*errors: OperationError) -> OperationResult

Parameters

Name Description
*errors
Required

Variable number of OperationError instances.

Returns

Type Description

An OperationResult indicating a failed operation.

success

Return an OperationResult indicating a successful operation.

static success() -> OperationResult

Returns

Type Description

An OperationResult indicating a successful operation.

Attributes

errors

Get the list of errors that occurred during the operation.

Note

This property returns a defensive copy of the internal error list

to prevent external modifications, which is especially important for

protecting the singleton instance returned by success().

Returns

Type Description

A copy of the list of operation errors.

succeeded

Get a flag indicating whether the operation succeeded.

Returns

Type Description

True if the operation succeeded, otherwise False.