Skip to content

Commit 801bd21

Browse files
committed
More error messages for syncv2
1 parent 07eae00 commit 801bd21

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

unison-cli/src/Unison/CommandLine/OutputMessages.hs

+61-6
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ import Unison.Server.Backend (ShallowListEntry (..), TypeEntry (..))
117117
import Unison.Server.Backend qualified as Backend
118118
import Unison.Server.SearchResultPrime qualified as SR'
119119
import Unison.Share.Sync.Types qualified as Share (CodeserverTransportError (..), GetCausalHashByPathError (..), PullError (..))
120+
import Unison.Share.Sync.Types qualified as Sync
120121
import Unison.Sync.Types qualified as Share
122+
import Unison.SyncV2.Types qualified as SyncV2
121123
import Unison.Syntax.DeclPrinter qualified as DeclPrinter
122124
import Unison.Syntax.HashQualified qualified as HQ (toText, unsafeFromVar)
123125
import Unison.Syntax.Name qualified as Name (toText)
@@ -2259,8 +2261,9 @@ notifyUser dir = \case
22592261
]
22602262
Literal message -> pure message
22612263
SyncPullError syncErr ->
2262-
-- TODO: Better error message
2263-
pure (P.shown syncErr)
2264+
case syncErr of
2265+
Sync.TransportError te -> pure (prettyTransportError te)
2266+
Sync.SyncError pullErr -> pure (prettyPullV2Error pullErr)
22642267

22652268
prettyShareError :: ShareError -> Pretty
22662269
prettyShareError =
@@ -2280,6 +2283,26 @@ prettyDownloadEntitiesError = \case
22802283
Share.DownloadEntitiesProjectNotFound project -> shareProjectNotFound project
22812284
Share.DownloadEntitiesEntityValidationFailure err -> prettyEntityValidationFailure err
22822285

2286+
prettyBranchRef :: SyncV2.BranchRef -> Pretty
2287+
prettyBranchRef (SyncV2.BranchRef txt) = P.blue (P.text txt)
2288+
2289+
prettyDownloadEntitiesErrorV2 :: SyncV2.DownloadEntitiesError -> Pretty
2290+
prettyDownloadEntitiesErrorV2 = \case
2291+
SyncV2.DownloadEntitiesNoReadPermission branchRef -> prettyBranchRef branchRef
2292+
SyncV2.DownloadEntitiesUserNotFound userHandle -> shareUserNotFound (Share.RepoInfo userHandle)
2293+
SyncV2.DownloadEntitiesProjectNotFound project -> shareProjectNotFound project
2294+
SyncV2.DownloadEntitiesEntityValidationFailure err -> prettyEntityValidationFailure err
2295+
SyncV2.DownloadEntitiesInvalidBranchRef msg ref -> prettyInvalidBranchRef msg ref
2296+
2297+
prettyInvalidBranchRef :: Text -> SyncV2.BranchRef -> Pretty
2298+
prettyInvalidBranchRef msg (SyncV2.BranchRef txt) =
2299+
P.wrap $
2300+
"The server sent an invalid branch reference."
2301+
<> "The error was:"
2302+
<> P.text msg
2303+
<> "The branch reference was:"
2304+
<> P.text txt
2305+
22832306
prettyGetCausalHashByPathError :: Share.GetCausalHashByPathError -> Pretty
22842307
prettyGetCausalHashByPathError = \case
22852308
Share.GetCausalHashByPathErrorNoReadPermission sharePath -> noReadPermissionForPath sharePath
@@ -2293,6 +2316,38 @@ prettyPullError = \case
22932316
Share.PullError'NoHistoryAtPath sharePath ->
22942317
P.wrap $ P.text "The server didn't find anything at" <> prettySharePath sharePath
22952318

2319+
prettyPullV2Error :: SyncV2.PullError -> Pretty
2320+
prettyPullV2Error = \case
2321+
SyncV2.PullError'DownloadEntities err -> prettyDownloadEntitiesErrorV2 err
2322+
SyncV2.PullError'Sync syncErr -> prettySyncErrorV2 syncErr
2323+
2324+
prettySyncErrorV2 :: SyncV2.SyncError -> Pretty
2325+
prettySyncErrorV2 = \case
2326+
SyncV2.SyncErrorExpectedResultNotInMain hash ->
2327+
P.wrap $
2328+
"The sync finished, but I'm missing an entity I expected."
2329+
<> "The missing hash is:"
2330+
<> prettyCausalHash hash
2331+
SyncV2.SyncErrorDeserializationFailure failure ->
2332+
P.wrap $
2333+
"Failed to decode a response from the server."
2334+
<> "The error was:"
2335+
<> P.shown failure
2336+
SyncV2.SyncErrorMissingInitialChunk ->
2337+
P.wrap "The server didn't send the initial chunk of the response."
2338+
SyncV2.SyncErrorMisplacedInitialChunk ->
2339+
P.wrap "The server sent the initial chunk of the response in the wrong place."
2340+
SyncV2.SyncErrorStreamFailure msg ->
2341+
P.wrap $
2342+
"Failed to stream data from the server."
2343+
<> "The error was:"
2344+
<> P.text msg
2345+
SyncV2.SyncErrorUnsupportedVersion version ->
2346+
P.wrap $
2347+
"The server sent a response with an unsupported version."
2348+
<> "The version was:"
2349+
<> P.shown version
2350+
22962351
prettyUploadEntitiesError :: Share.UploadEntitiesError -> Pretty
22972352
prettyUploadEntitiesError = \case
22982353
Share.UploadEntitiesError'EntityValidationFailure validationFailureErr -> prettyEntityValidationFailure validationFailureErr
@@ -2367,10 +2422,10 @@ prettyTransportError = \case
23672422
Share.UnexpectedResponse resp ->
23682423
unexpectedServerResponse resp
23692424
Share.StreamingError err ->
2370-
P.lines
2371-
[ ( "We encountered an error while streaming data from the code server: " <> P.text err),
2372-
P.red (P.text err)
2373-
]
2425+
P.lines
2426+
[ ("We encountered an error while streaming data from the code server: " <> P.text err),
2427+
P.red (P.text err)
2428+
]
23742429

23752430
unexpectedServerResponse :: Servant.ResponseF LazyByteString.ByteString -> P.Pretty Unison.Util.ColorText.ColorText
23762431
unexpectedServerResponse resp =

0 commit comments

Comments
 (0)