Skip to content

Commit b4adcb6

Browse files
committed
Add more error messages
1 parent a050338 commit b4adcb6

File tree

8 files changed

+77
-29
lines changed

8 files changed

+77
-29
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

+1-5
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,7 @@ loop e = do
695695
SyncV2.handleSyncFromFile description syncFileSrc projectBranchName
696696
SyncFromCodebaseI srcCodebasePath srcBranch destBranch -> do
697697
description <- inputDescription input
698-
let srcBranch' =
699-
srcBranch & over #project \case
700-
Nothing -> error "todo"
701-
Just proj -> proj
702-
SyncV2.handleSyncFromCodebase description srcCodebasePath srcBranch' destBranch
698+
SyncV2.handleSyncFromCodebase description srcCodebasePath srcBranch destBranch
703699
ListDependentsI hq -> handleDependents hq
704700
ListDependenciesI hq -> handleDependencies hq
705701
NamespaceDependenciesI path -> handleNamespaceDependencies path

unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs

+7-5
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ handleSyncFromCodebase description srcCodebasePath srcBranch destBranch = do
5757
branch <- MaybeT (Q.loadProjectBranchByName (project ^. #projectId) srcBranchName)
5858
lift $ Project.getProjectBranchCausalHash branch
5959
case maySrcCausalHash of
60-
Nothing -> pure $ Left (error "Todo proper error")
60+
Nothing -> pure $ Left (Output.SyncFromCodebaseMissingProjectBranch srcBranch)
6161
Just srcCausalHash -> do
6262
let shouldValidate = True
63-
fmap (const srcCausalHash) <$> liftIO (SyncV2.syncFromCodebase shouldValidate srcConn codebase srcCausalHash)
63+
Right . fmap (const srcCausalHash) <$> liftIO (SyncV2.syncFromCodebase shouldValidate srcConn codebase srcCausalHash)
6464

6565
case r of
66-
Left _err -> pure $ error "Todo proper error"
67-
Right (Left syncErr) -> Cli.respond (Output.SyncPullError syncErr)
68-
Right (Right causalHash) -> do
66+
Left openCodebaseErr -> Cli.respond (Output.OpenCodebaseError srcCodebasePath openCodebaseErr)
67+
Right (Left errOutput) -> Cli.respond errOutput
68+
Right (Right (Right causalHash)) -> do
6969
Cli.setProjectBranchRootToCausalHash (projectBranch ^. #branch) description causalHash
70+
Right (Right (Left syncErr)) -> do
71+
Cli.respond (Output.SyncPullError syncErr)

unison-cli/src/Unison/Codebase/Editor/Input.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ data Input
128128
| PushRemoteBranchI PushRemoteBranchInput
129129
| SyncToFileI FilePath (ProjectAndBranch (Maybe ProjectName) (Maybe ProjectBranchName))
130130
| SyncFromFileI FilePath UnresolvedProjectBranch
131-
| SyncFromCodebaseI FilePath UnresolvedProjectBranch UnresolvedProjectBranch
131+
| SyncFromCodebaseI FilePath (ProjectAndBranch ProjectName ProjectBranchName) UnresolvedProjectBranch
132132
| ResetI (BranchId2 {- namespace to reset it to -}) (Maybe UnresolvedProjectBranch {- ProjectBranch to reset -})
133133
| -- | used in Welcome module to give directions to user
134134
--

unison-cli/src/Unison/Codebase/Editor/Output.hs

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import U.Codebase.Sqlite.ProjectReflog qualified as ProjectReflog
3535
import Unison.Auth.Types (CredentialFailure)
3636
import Unison.Cli.MergeTypes (MergeSourceAndTarget, MergeSourceOrTarget)
3737
import Unison.Cli.Share.Projects.Types qualified as Share
38+
import Unison.Codebase (CodebasePath)
3839
import Unison.Codebase.Editor.Input
3940
import Unison.Codebase.Editor.Output.BranchDiff (BranchDiffOutput)
4041
import Unison.Codebase.Editor.Output.BranchDiff qualified as BD
@@ -43,6 +44,7 @@ import Unison.Codebase.Editor.RemoteRepo
4344
import Unison.Codebase.Editor.SlurpResult (SlurpResult (..))
4445
import Unison.Codebase.Editor.SlurpResult qualified as SR
4546
import Unison.Codebase.Editor.StructuredArgument (StructuredArgument)
47+
import Unison.Codebase.Init.OpenCodebaseError (OpenCodebaseError)
4648
import Unison.Codebase.IntegrityCheck (IntegrityResult (..))
4749
import Unison.Codebase.Path (Path')
4850
import Unison.Codebase.Path qualified as Path
@@ -442,6 +444,8 @@ data Output
442444
-- ephemeral progress messages that are just simple strings like "Loading branch..."
443445
Literal !(P.Pretty P.ColorText)
444446
| SyncPullError (Sync.SyncError SyncV2.PullError)
447+
| SyncFromCodebaseMissingProjectBranch (ProjectAndBranch ProjectName ProjectBranchName)
448+
| OpenCodebaseError CodebasePath OpenCodebaseError
445449

446450
data MoreEntriesThanShown = MoreEntriesThanShown | AllEntriesShown
447451
deriving (Eq, Show)
@@ -681,6 +685,8 @@ isFailure o = case o of
681685
IncoherentDeclDuringUpdate {} -> True
682686
Literal _ -> False
683687
SyncPullError {} -> True
688+
SyncFromCodebaseMissingProjectBranch {} -> True
689+
OpenCodebaseError {} -> True
684690

685691
isNumberedFailure :: NumberedOutput -> Bool
686692
isNumberedFailure = \case

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,23 @@ handleBranchWithOptionalProject =
773773
otherNumArg -> Left $ wrongStructuredArgument "a project branch" otherNumArg
774774
)
775775

776+
handleBranchWithProject :: I.Argument -> Either (P.Pretty CT.ColorText) (ProjectAndBranch ProjectName ProjectBranchName)
777+
handleBranchWithProject =
778+
either
779+
( \str ->
780+
Text.pack str
781+
& tryInto @(These ProjectName ProjectBranchName)
782+
& first (const $ expectedButActually' "a project branch" str)
783+
>>= \case
784+
These project branch -> pure $ ProjectAndBranch project branch
785+
That _branch -> Left $ expectedButActually' "a project branch" str
786+
This _project -> Left $ expectedButActually' "a project branch" str
787+
)
788+
( \case
789+
SA.ProjectBranch (ProjectAndBranch (Just proj) branch) -> pure $ ProjectAndBranch proj branch
790+
otherNumArg -> Left $ wrongStructuredArgument "a project branch" otherNumArg
791+
)
792+
776793
mergeBuiltins :: InputPattern
777794
mergeBuiltins =
778795
InputPattern
@@ -2192,7 +2209,7 @@ syncFromCodebase =
21922209
]
21932210
),
21942211
parse = \case
2195-
[codebaseLocation, branchToSync, destinationBranch] -> Input.SyncFromCodebaseI <$> unsupportedStructuredArgument makeStandalone "a file name" codebaseLocation <*> handleBranchWithOptionalProject branchToSync <*> handleBranchWithOptionalProject destinationBranch
2212+
[codebaseLocation, branchToSync, destinationBranch] -> Input.SyncFromCodebaseI <$> unsupportedStructuredArgument makeStandalone "a file name" codebaseLocation <*> handleBranchWithProject branchToSync <*> handleBranchWithOptionalProject destinationBranch
21962213
args -> wrongArgsLength "three arguments" args
21972214
}
21982215
where

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

+27
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import Unison.Codebase.Editor.Output.PushPull qualified as PushPull
6565
import Unison.Codebase.Editor.SlurpResult qualified as SlurpResult
6666
import Unison.Codebase.Editor.StructuredArgument (StructuredArgument)
6767
import Unison.Codebase.Editor.StructuredArgument qualified as SA
68+
import Unison.Codebase.Init.OpenCodebaseError qualified as CodebaseInit
6869
import Unison.Codebase.IntegrityCheck (IntegrityResult (..), prettyPrintIntegrityErrors)
6970
import Unison.Codebase.Patch qualified as Patch
7071
import Unison.Codebase.Path qualified as Path
@@ -974,6 +975,7 @@ notifyUser dir = \case
974975
-- defs in the codebase. In some cases it's fine for bindings to
975976
-- shadow codebase names, but you don't want it to capture them in
976977
-- the decompiled output.
978+
977979
let prettyBindings =
978980
P.bracket . P.lines $
979981
P.wrap "The watch expression(s) reference these definitions:"
@@ -2264,6 +2266,31 @@ notifyUser dir = \case
22642266
case syncErr of
22652267
Sync.TransportError te -> pure (prettyTransportError te)
22662268
Sync.SyncError pullErr -> pure (prettyPullV2Error pullErr)
2269+
SyncFromCodebaseMissingProjectBranch projectBranch ->
2270+
pure . P.wrap $
2271+
"I couldn't sync from the codebase because the project branch"
2272+
<> prettyProjectAndBranchName projectBranch
2273+
<> "doesn't exist."
2274+
OpenCodebaseError codebasePath err -> case err of
2275+
CodebaseInit.OpenCodebaseDoesntExist ->
2276+
pure . P.wrap $ "I couldn't find a valid codebase at " <> prettyFilePath codebasePath
2277+
CodebaseInit.OpenCodebaseUnknownSchemaVersion schemaVersion ->
2278+
pure . P.wrap . P.lines $
2279+
[ "I couldn't open the codebase at " <> prettyFilePath codebasePath <> ".",
2280+
"The schema version appears to be newer than the current UCM version can support.",
2281+
"You may need to upgrade UCM. The codebase is at schema version: " <> P.shown schemaVersion
2282+
]
2283+
CodebaseInit.OpenCodebaseFileLockFailed -> do
2284+
pure . P.wrap . P.lines $
2285+
[ "I couldn't open the codebase at " <> prettyFilePath codebasePath,
2286+
"It appears another process is using that codebase, please close other UCM instances and try again."
2287+
]
2288+
CodebaseInit.OpenCodebaseRequiresMigration currentSV requiredSV ->
2289+
pure . P.wrap . P.lines $
2290+
[ "I couldn't open the codebase at " <> prettyFilePath codebasePath,
2291+
"The codebase is at schema version " <> P.shown currentSV <> " but UCM requires schema version " <> P.shown requiredSV <> ".",
2292+
"Please open the other codebase with UCM directly to upgrade it to the latest version, then try again."
2293+
]
22672294

22682295
prettyShareError :: ShareError -> Pretty
22692296
prettyShareError =

unison-runtime/src/Unison/Runtime/Interface.hs

+16-15
Original file line numberDiff line numberDiff line change
@@ -1440,18 +1440,19 @@ buildSCache crsrc cssrc cacheableCombs trsrc ftm fty int rtmsrc rtysrc sndbx =
14401440
restrictTyR m = Map.restrictKeys m typeRefs
14411441

14421442
standalone :: CCache -> Word64 -> IO StoredCache
1443-
standalone cc init = readTVarIO (combRefs cc) >>= \crs ->
1444-
case EC.lookup init crs of
1445-
Just rinit ->
1446-
buildSCache crs
1447-
<$> readTVarIO (srcCombs cc)
1448-
<*> readTVarIO (cacheableCombs cc)
1449-
<*> readTVarIO (tagRefs cc)
1450-
<*> readTVarIO (freshTm cc)
1451-
<*> readTVarIO (freshTy cc)
1452-
<*> (readTVarIO (intermed cc) >>= traceNeeded rinit)
1453-
<*> readTVarIO (refTm cc)
1454-
<*> readTVarIO (refTy cc)
1455-
<*> readTVarIO (sandbox cc)
1456-
Nothing ->
1457-
die $ "standalone: unknown combinator: " ++ show init
1443+
standalone cc init =
1444+
readTVarIO (combRefs cc) >>= \crs ->
1445+
case EC.lookup init crs of
1446+
Just rinit ->
1447+
buildSCache crs
1448+
<$> readTVarIO (srcCombs cc)
1449+
<*> readTVarIO (cacheableCombs cc)
1450+
<*> readTVarIO (tagRefs cc)
1451+
<*> readTVarIO (freshTm cc)
1452+
<*> readTVarIO (freshTy cc)
1453+
<*> (readTVarIO (intermed cc) >>= traceNeeded rinit)
1454+
<*> readTVarIO (refTm cc)
1455+
<*> readTVarIO (refTy cc)
1456+
<*> readTVarIO (sandbox cc)
1457+
Nothing ->
1458+
die $ "standalone: unknown combinator: " ++ show init

unison-share-api/src/Unison/SyncV2/Types.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ newtype Version = Version Word16
165165
deriving stock (Show)
166166
deriving newtype (Eq, Ord, Serialise)
167167

168-
data StreamInitInfo
169-
= StreamInitInfo
168+
data StreamInitInfo = StreamInitInfo
170169
{ version :: Version,
171170
entitySorting :: EntitySorting,
172171
numEntities :: Maybe Word64,

0 commit comments

Comments
 (0)