-- | Types used by the UCM client during sync.
module Unison.Share.Sync.Types
  ( CodeserverTransportError (..),
    GetCausalHashByPathError (..),
    PullError (..),
    SyncError (..),
  )
where

import Servant.Client qualified as Servant
import Unison.Prelude
import Unison.Sync.Types qualified as Share

-- | An error occurred while pulling code from Unison Share.
data PullError
  = PullError'DownloadEntities Share.DownloadEntitiesError
  | PullError'GetCausalHash GetCausalHashByPathError
  | PullError'NoHistoryAtPath Share.Path
  deriving stock (Int -> PullError -> ShowS
[PullError] -> ShowS
PullError -> String
(Int -> PullError -> ShowS)
-> (PullError -> String)
-> ([PullError] -> ShowS)
-> Show PullError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PullError -> ShowS
showsPrec :: Int -> PullError -> ShowS
$cshow :: PullError -> String
show :: PullError -> String
$cshowList :: [PullError] -> ShowS
showList :: [PullError] -> ShowS
Show)

-- | An error occurred when getting causal hash by path.
data GetCausalHashByPathError
  = -- | The user does not have permission to read this path.
    GetCausalHashByPathErrorNoReadPermission Share.Path
  | -- | The repo info was invalid. (err, repoInfo)
    GetCausalHashByPathErrorInvalidRepoInfo Text Share.RepoInfo
  | -- | The user was not found.
    GetCausalHashByPathErrorUserNotFound Share.RepoInfo
  deriving (Int -> GetCausalHashByPathError -> ShowS
[GetCausalHashByPathError] -> ShowS
GetCausalHashByPathError -> String
(Int -> GetCausalHashByPathError -> ShowS)
-> (GetCausalHashByPathError -> String)
-> ([GetCausalHashByPathError] -> ShowS)
-> Show GetCausalHashByPathError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCausalHashByPathError -> ShowS
showsPrec :: Int -> GetCausalHashByPathError -> ShowS
$cshow :: GetCausalHashByPathError -> String
show :: GetCausalHashByPathError -> String
$cshowList :: [GetCausalHashByPathError] -> ShowS
showList :: [GetCausalHashByPathError] -> ShowS
Show)

-- | Generic Codeserver transport errors
data CodeserverTransportError
  = DecodeFailure Text Servant.Response
  | -- We try to catch permission failures in the endpoint's response type, but if any slip
    -- through they'll be translated as a PermissionDenied.
    PermissionDenied Text
  | RateLimitExceeded
  | Timeout
  | Unauthenticated Servant.BaseUrl
  | UnexpectedResponse Servant.Response
  | UnreachableCodeserver Servant.BaseUrl
  deriving stock (Int -> CodeserverTransportError -> ShowS
[CodeserverTransportError] -> ShowS
CodeserverTransportError -> String
(Int -> CodeserverTransportError -> ShowS)
-> (CodeserverTransportError -> String)
-> ([CodeserverTransportError] -> ShowS)
-> Show CodeserverTransportError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeserverTransportError -> ShowS
showsPrec :: Int -> CodeserverTransportError -> ShowS
$cshow :: CodeserverTransportError -> String
show :: CodeserverTransportError -> String
$cshowList :: [CodeserverTransportError] -> ShowS
showList :: [CodeserverTransportError] -> ShowS
Show)
  deriving anyclass (Show CodeserverTransportError
Typeable CodeserverTransportError
(Typeable CodeserverTransportError,
 Show CodeserverTransportError) =>
(CodeserverTransportError -> SomeException)
-> (SomeException -> Maybe CodeserverTransportError)
-> (CodeserverTransportError -> String)
-> Exception CodeserverTransportError
SomeException -> Maybe CodeserverTransportError
CodeserverTransportError -> String
CodeserverTransportError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: CodeserverTransportError -> SomeException
toException :: CodeserverTransportError -> SomeException
$cfromException :: SomeException -> Maybe CodeserverTransportError
fromException :: SomeException -> Maybe CodeserverTransportError
$cdisplayException :: CodeserverTransportError -> String
displayException :: CodeserverTransportError -> String
Exception)

data SyncError e
  = TransportError CodeserverTransportError
  | SyncError e
  deriving stock ((forall a b. (a -> b) -> SyncError a -> SyncError b)
-> (forall a b. a -> SyncError b -> SyncError a)
-> Functor SyncError
forall a b. a -> SyncError b -> SyncError a
forall a b. (a -> b) -> SyncError a -> SyncError b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> SyncError a -> SyncError b
fmap :: forall a b. (a -> b) -> SyncError a -> SyncError b
$c<$ :: forall a b. a -> SyncError b -> SyncError a
<$ :: forall a b. a -> SyncError b -> SyncError a
Functor, Int -> SyncError e -> ShowS
[SyncError e] -> ShowS
SyncError e -> String
(Int -> SyncError e -> ShowS)
-> (SyncError e -> String)
-> ([SyncError e] -> ShowS)
-> Show (SyncError e)
forall e. Show e => Int -> SyncError e -> ShowS
forall e. Show e => [SyncError e] -> ShowS
forall e. Show e => SyncError e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall e. Show e => Int -> SyncError e -> ShowS
showsPrec :: Int -> SyncError e -> ShowS
$cshow :: forall e. Show e => SyncError e -> String
show :: SyncError e -> String
$cshowList :: forall e. Show e => [SyncError e] -> ShowS
showList :: [SyncError e] -> ShowS
Show)