Skip to content

Commit b0fdc4a

Browse files
committed
[raft/scd] Return result and error in TransactWithResult
1 parent 2056183 commit b0fdc4a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

pkg/store/store.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ func DecodeJSON[T OperationRequest](buf []byte) (OperationRequest, error) {
5454
}
5555

5656
// TransactWithResult wraps Store.Transact and casts the result to ResultType, avoiding a cast at every call site.
57+
// The result (if any) is returned alongside a non-nil error since some operations may return both (e.g. AirspaceConflictResponse in CreateOperationalIntentReference).
5758
func TransactWithResult[R any, ResultType any](ctx context.Context, store Store[R], request OperationRequest) (ResultType, error) {
5859
var empty ResultType
5960
transactionResult, err := store.Transact(ctx, request)
60-
if err != nil {
61-
return empty, err
62-
}
6361
resultType, ok := transactionResult.(ResultType)
6462
if !ok {
63+
if err != nil {
64+
return empty, err
65+
}
6566
return empty, stacktrace.NewError("unexpected result type %T, want %T", transactionResult, empty)
6667
}
67-
return resultType, nil
68+
return resultType, err
6869
}
6970

7071
// FuncOperation wraps a closure as an OperationRequest for gradual migration.

0 commit comments

Comments
 (0)