Skip to content

Commit 04a38e8

Browse files
committed
remote: add opSuccess serializer for StoreReply ()
1 parent 48697e1 commit 04a38e8

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module System.Nix.Store.Remote.Serializer
8484
, storeRequest
8585
-- ** Reply
8686
, ReplySError(..)
87+
, opSuccess
8788
-- *** Realisation
8889
, derivationOutputTyped
8990
, realisation
@@ -1340,7 +1341,7 @@ storeRequest = Serializer
13401341
-> m a
13411342
reserved = throwError . RequestSError_ReservedOp
13421343

1343-
-- * Reply
1344+
-- ** Reply
13441345

13451346
data ReplySError
13461347
= ReplySError_PrimGet SError
@@ -1351,6 +1352,7 @@ data ReplySError
13511352
| ReplySError_Missing SError
13521353
| ReplySError_Realisation SError
13531354
| ReplySError_RealisationWithId SError
1355+
| ReplySError_UnexpectedFalseOpSuccess
13541356
deriving (Eq, Ord, Generic, Show)
13551357

13561358
mapGetER
@@ -1365,6 +1367,20 @@ mapPutER
13651367
-> SerialT r ReplySError m a
13661368
mapPutER = mapErrorST ReplySError_PrimPut
13671369

1370+
-- | Parse a bool returned at the end of simple operations.
1371+
-- This is always 1 (@True@) so we assert that it really is so.
1372+
-- Errors for these operations are indicated via @Logger_Error@.
1373+
opSuccess :: NixSerializer r ReplySError ()
1374+
opSuccess = Serializer
1375+
{ getS = do
1376+
retCode <- mapGetER $ getS bool
1377+
Control.Monad.unless
1378+
(retCode == True)
1379+
$ throwError ReplySError_UnexpectedFalseOpSuccess
1380+
pure ()
1381+
, putS = \_ -> mapPutER $ putS bool True
1382+
}
1383+
13681384
-- *** Realisation
13691385

13701386
derivationOutputTyped :: NixSerializer r ReplySError (System.Nix.Realisation.DerivationOutput OutputName)

hnix-store-remote/src/System/Nix/Store/Remote/Types/StoreReply.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class StoreReply a where
2222
)
2323
=> NixSerializer r ReplySError a
2424

25+
instance StoreReply () where
26+
getReplyS = opSuccess
27+
2528
instance StoreReply Bool where
2629
getReplyS = mapPrimE bool
2730

hnix-store-remote/tests/NixSerializerSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ spec = parallel $ do
150150
$ roundtripSReader @TestStoreConfig storeRequest testStoreConfig
151151

152152
describe "StoreReply" $ do
153+
prop "()" $ roundtripS opSuccess
153154
prop "GCResult" $ roundtripSReader @StoreDir gcResult
154155
prop "Missing" $ roundtripSReader @StoreDir missing
155156
prop "Maybe (Metadata StorePath)" $ roundtripSReader @StoreDir maybePathMetadata

0 commit comments

Comments
 (0)