Skip to content

Commit

Permalink
Add more error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Jan 17, 2025
1 parent a050338 commit b4adcb6
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 29 deletions.
6 changes: 1 addition & 5 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/SyncV2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/Codebase/Editor/Input.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand Down
6 changes: 6 additions & 0 deletions unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -681,6 +685,8 @@ isFailure o = case o of
IncoherentDeclDuringUpdate {} -> True
Literal _ -> False
SyncPullError {} -> True
SyncFromCodebaseMissingProjectBranch {} -> True
OpenCodebaseError {} -> True

isNumberedFailure :: NumberedOutput -> Bool
isNumberedFailure = \case
Expand Down
19 changes: 18 additions & 1 deletion unison-cli/src/Unison/CommandLine/InputPatterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:"
Expand Down Expand Up @@ -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 =
Expand Down
31 changes: 16 additions & 15 deletions unison-runtime/src/Unison/Runtime/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions unison-share-api/src/Unison/SyncV2/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b4adcb6

Please sign in to comment.