diff --git a/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs b/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs index c03fa187..e61b404c 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs @@ -57,6 +57,7 @@ import Data.Text (Text) import Data.Time (UTCTime) import qualified Control.Monad +import qualified Control.Monad.Reader import qualified Data.HashSet import qualified Data.Map.Strict import qualified Data.Set @@ -262,9 +263,11 @@ logger = Serializer LoggerOpCode_Last -> pure Logger_Last LoggerOpCode_Error -> do - errorMessage <- getS byteString - errorExitStatus <- getS int - pure Logger_Error{..} + pv <- Control.Monad.Reader.asks hasProtoVersion + Logger_Error <$> + if protoVersion_minor pv >= 26 + then Right <$> getS errorInfo + else Left <$> getS basicError LoggerOpCode_StartActivity -> do startActivityID <- getS activityID startActivityVerbosity <- getS verbosity @@ -293,10 +296,13 @@ logger = Serializer putS byteString s Logger_Last -> putS loggerOpCode LoggerOpCode_Last - Logger_Error{..} -> do + Logger_Error basicOrInfo -> do putS loggerOpCode LoggerOpCode_Error - putS byteString errorMessage - putS int errorExitStatus + -- TODO: throwError if we try to send + -- ErrorInfo to client which has no support for it + case basicOrInfo of + Left e -> putS basicError e + Right e -> putS errorInfo e Logger_StartActivity{..} -> do putS loggerOpCode LoggerOpCode_StartActivity putS activityID startActivityID diff --git a/hnix-store-remote/src/System/Nix/Store/Remote/Types/Logger.hs b/hnix-store-remote/src/System/Nix/Store/Remote/Types/Logger.hs index d648492b..779909cb 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote/Types/Logger.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote/Types/Logger.hs @@ -83,10 +83,7 @@ data Logger | Logger_Read Int -- data needed from source | Logger_Write ByteString -- data for sink | Logger_Last - | Logger_Error - { errorExitStatus :: Int - , errorMessage :: ByteString - } + | Logger_Error (Either BasicError ErrorInfo) | Logger_StartActivity { startActivityID :: ActivityID , startActivityVerbosity :: Verbosity diff --git a/hnix-store-remote/tests/NixSerializerSpec.hs b/hnix-store-remote/tests/NixSerializerSpec.hs index 4f860549..4ba37953 100644 --- a/hnix-store-remote/tests/NixSerializerSpec.hs +++ b/hnix-store-remote/tests/NixSerializerSpec.hs @@ -6,7 +6,7 @@ import Data.Fixed (Uni) import Data.Time (NominalDiffTime) import Test.Hspec (Expectation, Spec, describe, parallel, shouldBe) import Test.Hspec.QuickCheck (prop) -import Test.QuickCheck (arbitrary, forAll, suchThat) +import Test.QuickCheck (Gen, arbitrary, forAll, suchThat) import Test.QuickCheck.Instances () import qualified Data.Time.Clock.POSIX @@ -17,7 +17,7 @@ import System.Nix.Arbitrary () import System.Nix.Derivation (Derivation(inputDrvs)) import System.Nix.Store.Remote.Arbitrary () import System.Nix.Store.Remote.Serializer -import System.Nix.Store.Remote.Types (ErrorInfo(..), ProtoVersion, Trace(..)) +import System.Nix.Store.Remote.Types (ErrorInfo(..), Logger(..), ProtoVersion(..), Trace(..)) -- | Test for roundtrip using @NixSerializer@ roundtripSReader @@ -109,4 +109,16 @@ spec = parallel $ do $ roundtripS errorInfo prop "LoggerOpCode" $ roundtripS loggerOpCode prop "Verbosity" $ roundtripS verbosity - prop "Logger" $ roundtripSReader @ProtoVersion logger + prop "Logger" + $ forAll (arbitrary :: Gen ProtoVersion) + $ \pv -> + forAll (arbitrary `suchThat` errorInfoIf (protoVersion_minor pv >= 26)) + $ roundtripSReader logger pv + where + errorInfoIf True (Logger_Error (Right x)) = noJust0s x + errorInfoIf False (Logger_Error (Left _)) = True + errorInfoIf _ (Logger_Error _) = False + errorInfoIf _ _ = True + noJust0s ErrorInfo{..} = + errorInfoPosition /= Just 0 + && all ((/= Just 0) . tracePosition) errorInfoTraces