diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs index e3e78c6575..c0cc9a8dd6 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs @@ -695,11 +695,7 @@ loop e = do SyncV2.handleSyncFromFile description syncFileSrc projectBranchName SyncFromCodebaseI srcCodebasePath srcBranch destBranch -> do description <- inputDescription input - let srcBranch' = - srcBranch & over #project \case - Nothing -> error "todo" - Just proj -> proj - SyncV2.handleSyncFromCodebase description srcCodebasePath srcBranch' destBranch + SyncV2.handleSyncFromCodebase description srcCodebasePath srcBranch destBranch ListDependentsI hq -> handleDependents hq ListDependenciesI hq -> handleDependencies hq NamespaceDependenciesI path -> handleNamespaceDependencies path diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs index df5a2480a3..f34a64302a 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs @@ -57,13 +57,15 @@ handleSyncFromCodebase description srcCodebasePath srcBranch destBranch = do branch <- MaybeT (Q.loadProjectBranchByName (project ^. #projectId) srcBranchName) lift $ Project.getProjectBranchCausalHash branch case maySrcCausalHash of - Nothing -> pure $ Left (error "Todo proper error") + Nothing -> pure $ Left (Output.SyncFromCodebaseMissingProjectBranch srcBranch) Just srcCausalHash -> do let shouldValidate = True - fmap (const srcCausalHash) <$> liftIO (SyncV2.syncFromCodebase shouldValidate srcConn codebase srcCausalHash) + Right . fmap (const srcCausalHash) <$> liftIO (SyncV2.syncFromCodebase shouldValidate srcConn codebase srcCausalHash) case r of - Left _err -> pure $ error "Todo proper error" - Right (Left syncErr) -> Cli.respond (Output.SyncPullError syncErr) - Right (Right causalHash) -> do + Left openCodebaseErr -> Cli.respond (Output.OpenCodebaseError srcCodebasePath openCodebaseErr) + Right (Left errOutput) -> Cli.respond errOutput + Right (Right (Right causalHash)) -> do Cli.setProjectBranchRootToCausalHash (projectBranch ^. #branch) description causalHash + Right (Right (Left syncErr)) -> do + Cli.respond (Output.SyncPullError syncErr) diff --git a/unison-cli/src/Unison/Codebase/Editor/Input.hs b/unison-cli/src/Unison/Codebase/Editor/Input.hs index 684a5ac1ea..c496b5ba0d 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Input.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Input.hs @@ -128,7 +128,7 @@ data Input | PushRemoteBranchI PushRemoteBranchInput | SyncToFileI FilePath (ProjectAndBranch (Maybe ProjectName) (Maybe ProjectBranchName)) | SyncFromFileI FilePath UnresolvedProjectBranch - | SyncFromCodebaseI FilePath UnresolvedProjectBranch UnresolvedProjectBranch + | SyncFromCodebaseI FilePath (ProjectAndBranch ProjectName ProjectBranchName) UnresolvedProjectBranch | ResetI (BranchId2 {- namespace to reset it to -}) (Maybe UnresolvedProjectBranch {- ProjectBranch to reset -}) | -- | used in Welcome module to give directions to user -- diff --git a/unison-cli/src/Unison/Codebase/Editor/Output.hs b/unison-cli/src/Unison/Codebase/Editor/Output.hs index 13c0a076cc..6b5f528869 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Output.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Output.hs @@ -35,6 +35,7 @@ import U.Codebase.Sqlite.ProjectReflog qualified as ProjectReflog import Unison.Auth.Types (CredentialFailure) import Unison.Cli.MergeTypes (MergeSourceAndTarget, MergeSourceOrTarget) import Unison.Cli.Share.Projects.Types qualified as Share +import Unison.Codebase (CodebasePath) import Unison.Codebase.Editor.Input import Unison.Codebase.Editor.Output.BranchDiff (BranchDiffOutput) import Unison.Codebase.Editor.Output.BranchDiff qualified as BD @@ -43,6 +44,7 @@ import Unison.Codebase.Editor.RemoteRepo import Unison.Codebase.Editor.SlurpResult (SlurpResult (..)) import Unison.Codebase.Editor.SlurpResult qualified as SR import Unison.Codebase.Editor.StructuredArgument (StructuredArgument) +import Unison.Codebase.Init.OpenCodebaseError (OpenCodebaseError) import Unison.Codebase.IntegrityCheck (IntegrityResult (..)) import Unison.Codebase.Path (Path') import Unison.Codebase.Path qualified as Path @@ -442,6 +444,8 @@ data Output -- ephemeral progress messages that are just simple strings like "Loading branch..." Literal !(P.Pretty P.ColorText) | SyncPullError (Sync.SyncError SyncV2.PullError) + | SyncFromCodebaseMissingProjectBranch (ProjectAndBranch ProjectName ProjectBranchName) + | OpenCodebaseError CodebasePath OpenCodebaseError data MoreEntriesThanShown = MoreEntriesThanShown | AllEntriesShown deriving (Eq, Show) @@ -681,6 +685,8 @@ isFailure o = case o of IncoherentDeclDuringUpdate {} -> True Literal _ -> False SyncPullError {} -> True + SyncFromCodebaseMissingProjectBranch {} -> True + OpenCodebaseError {} -> True isNumberedFailure :: NumberedOutput -> Bool isNumberedFailure = \case diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index f2fc24cf7d..40a82c2241 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -773,6 +773,23 @@ handleBranchWithOptionalProject = otherNumArg -> Left $ wrongStructuredArgument "a project branch" otherNumArg ) +handleBranchWithProject :: I.Argument -> Either (P.Pretty CT.ColorText) (ProjectAndBranch ProjectName ProjectBranchName) +handleBranchWithProject = + either + ( \str -> + Text.pack str + & tryInto @(These ProjectName ProjectBranchName) + & first (const $ expectedButActually' "a project branch" str) + >>= \case + These project branch -> pure $ ProjectAndBranch project branch + That _branch -> Left $ expectedButActually' "a project branch" str + This _project -> Left $ expectedButActually' "a project branch" str + ) + ( \case + SA.ProjectBranch (ProjectAndBranch (Just proj) branch) -> pure $ ProjectAndBranch proj branch + otherNumArg -> Left $ wrongStructuredArgument "a project branch" otherNumArg + ) + mergeBuiltins :: InputPattern mergeBuiltins = InputPattern @@ -2192,7 +2209,7 @@ syncFromCodebase = ] ), parse = \case - [codebaseLocation, branchToSync, destinationBranch] -> Input.SyncFromCodebaseI <$> unsupportedStructuredArgument makeStandalone "a file name" codebaseLocation <*> handleBranchWithOptionalProject branchToSync <*> handleBranchWithOptionalProject destinationBranch + [codebaseLocation, branchToSync, destinationBranch] -> Input.SyncFromCodebaseI <$> unsupportedStructuredArgument makeStandalone "a file name" codebaseLocation <*> handleBranchWithProject branchToSync <*> handleBranchWithOptionalProject destinationBranch args -> wrongArgsLength "three arguments" args } where diff --git a/unison-cli/src/Unison/CommandLine/OutputMessages.hs b/unison-cli/src/Unison/CommandLine/OutputMessages.hs index 6b8c8a279a..2285c9b727 100644 --- a/unison-cli/src/Unison/CommandLine/OutputMessages.hs +++ b/unison-cli/src/Unison/CommandLine/OutputMessages.hs @@ -65,6 +65,7 @@ import Unison.Codebase.Editor.Output.PushPull qualified as PushPull import Unison.Codebase.Editor.SlurpResult qualified as SlurpResult import Unison.Codebase.Editor.StructuredArgument (StructuredArgument) import Unison.Codebase.Editor.StructuredArgument qualified as SA +import Unison.Codebase.Init.OpenCodebaseError qualified as CodebaseInit import Unison.Codebase.IntegrityCheck (IntegrityResult (..), prettyPrintIntegrityErrors) import Unison.Codebase.Patch qualified as Patch import Unison.Codebase.Path qualified as Path @@ -974,6 +975,7 @@ notifyUser dir = \case -- defs in the codebase. In some cases it's fine for bindings to -- shadow codebase names, but you don't want it to capture them in -- the decompiled output. + let prettyBindings = P.bracket . P.lines $ P.wrap "The watch expression(s) reference these definitions:" @@ -2264,6 +2266,31 @@ notifyUser dir = \case case syncErr of Sync.TransportError te -> pure (prettyTransportError te) Sync.SyncError pullErr -> pure (prettyPullV2Error pullErr) + SyncFromCodebaseMissingProjectBranch projectBranch -> + pure . P.wrap $ + "I couldn't sync from the codebase because the project branch" + <> prettyProjectAndBranchName projectBranch + <> "doesn't exist." + OpenCodebaseError codebasePath err -> case err of + CodebaseInit.OpenCodebaseDoesntExist -> + pure . P.wrap $ "I couldn't find a valid codebase at " <> prettyFilePath codebasePath + CodebaseInit.OpenCodebaseUnknownSchemaVersion schemaVersion -> + pure . P.wrap . P.lines $ + [ "I couldn't open the codebase at " <> prettyFilePath codebasePath <> ".", + "The schema version appears to be newer than the current UCM version can support.", + "You may need to upgrade UCM. The codebase is at schema version: " <> P.shown schemaVersion + ] + CodebaseInit.OpenCodebaseFileLockFailed -> do + pure . P.wrap . P.lines $ + [ "I couldn't open the codebase at " <> prettyFilePath codebasePath, + "It appears another process is using that codebase, please close other UCM instances and try again." + ] + CodebaseInit.OpenCodebaseRequiresMigration currentSV requiredSV -> + pure . P.wrap . P.lines $ + [ "I couldn't open the codebase at " <> prettyFilePath codebasePath, + "The codebase is at schema version " <> P.shown currentSV <> " but UCM requires schema version " <> P.shown requiredSV <> ".", + "Please open the other codebase with UCM directly to upgrade it to the latest version, then try again." + ] prettyShareError :: ShareError -> Pretty prettyShareError = diff --git a/unison-runtime/src/Unison/Runtime/Interface.hs b/unison-runtime/src/Unison/Runtime/Interface.hs index dfa54e01e4..e8e1442836 100644 --- a/unison-runtime/src/Unison/Runtime/Interface.hs +++ b/unison-runtime/src/Unison/Runtime/Interface.hs @@ -1440,18 +1440,19 @@ buildSCache crsrc cssrc cacheableCombs trsrc ftm fty int rtmsrc rtysrc sndbx = restrictTyR m = Map.restrictKeys m typeRefs standalone :: CCache -> Word64 -> IO StoredCache -standalone cc init = readTVarIO (combRefs cc) >>= \crs -> - case EC.lookup init crs of - Just rinit -> - buildSCache crs - <$> readTVarIO (srcCombs cc) - <*> readTVarIO (cacheableCombs cc) - <*> readTVarIO (tagRefs cc) - <*> readTVarIO (freshTm cc) - <*> readTVarIO (freshTy cc) - <*> (readTVarIO (intermed cc) >>= traceNeeded rinit) - <*> readTVarIO (refTm cc) - <*> readTVarIO (refTy cc) - <*> readTVarIO (sandbox cc) - Nothing -> - die $ "standalone: unknown combinator: " ++ show init +standalone cc init = + readTVarIO (combRefs cc) >>= \crs -> + case EC.lookup init crs of + Just rinit -> + buildSCache crs + <$> readTVarIO (srcCombs cc) + <*> readTVarIO (cacheableCombs cc) + <*> readTVarIO (tagRefs cc) + <*> readTVarIO (freshTm cc) + <*> readTVarIO (freshTy cc) + <*> (readTVarIO (intermed cc) >>= traceNeeded rinit) + <*> readTVarIO (refTm cc) + <*> readTVarIO (refTy cc) + <*> readTVarIO (sandbox cc) + Nothing -> + die $ "standalone: unknown combinator: " ++ show init diff --git a/unison-share-api/src/Unison/SyncV2/Types.hs b/unison-share-api/src/Unison/SyncV2/Types.hs index 419918e107..2f4432ee74 100644 --- a/unison-share-api/src/Unison/SyncV2/Types.hs +++ b/unison-share-api/src/Unison/SyncV2/Types.hs @@ -165,8 +165,7 @@ newtype Version = Version Word16 deriving stock (Show) deriving newtype (Eq, Ord, Serialise) -data StreamInitInfo - = StreamInitInfo +data StreamInitInfo = StreamInitInfo { version :: Version, entitySorting :: EntitySorting, numEntities :: Maybe Word64,