mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-09-11 18:05:56 +03:00
remote: handle errors in genericIncremental
This commit is contained in:
parent
c4315f1842
commit
6ebc2fcc5b
@ -46,6 +46,8 @@ data RemoteStoreError
|
||||
| RemoteStoreError_ClientVersionTooOld
|
||||
| RemoteStoreError_Disconnected
|
||||
| RemoteStoreError_GetAddrInfoFailed
|
||||
| RemoteStoreError_GenericIncrementalLeftovers ByteString -- when there are bytes left over after genericIncremental parser is done
|
||||
| RemoteStoreError_GenericIncrementalFail String ByteString -- when genericIncremental parser returns ((Fail msg leftover) :: Result)
|
||||
| RemoteStoreError_SerializerGet SError
|
||||
| RemoteStoreError_SerializerHandshake HandshakeSError
|
||||
| RemoteStoreError_SerializerLogger LoggerSError
|
||||
|
@ -20,7 +20,9 @@ import qualified Data.Serializer
|
||||
import qualified Data.Serialize.Get
|
||||
|
||||
genericIncremental
|
||||
:: MonadIO m
|
||||
:: ( MonadIO m
|
||||
, MonadError RemoteStoreError m
|
||||
)
|
||||
=> m ByteString
|
||||
-> Get a
|
||||
-> m a
|
||||
@ -28,11 +30,22 @@ genericIncremental getsome parser = do
|
||||
getsome >>= go . decoder
|
||||
where
|
||||
decoder = Data.Serialize.Get.runGetPartial parser
|
||||
go (Done _ leftover) | leftover /= mempty =
|
||||
throwError
|
||||
$ RemoteStoreError_GenericIncrementalLeftovers
|
||||
leftover
|
||||
|
||||
go (Done x _leftover) = pure x
|
||||
|
||||
go (Partial k) = do
|
||||
chunk <- getsome
|
||||
go (k chunk)
|
||||
go (Fail msg _leftover) = error msg
|
||||
|
||||
go (Fail msg leftover) =
|
||||
throwError
|
||||
$ RemoteStoreError_GenericIncrementalFail
|
||||
msg
|
||||
leftover
|
||||
|
||||
sockGet8
|
||||
:: ( MonadIO m
|
||||
|
Loading…
Reference in New Issue
Block a user