improve upgrade failure message

This commit is contained in:
Mitchell Rosen 2024-06-03 09:45:21 -04:00
parent 510e9dc6bb
commit 0635baa784
4 changed files with 72 additions and 13 deletions

View File

@ -12,6 +12,8 @@ import Data.Set qualified as Set
import Data.Text qualified as Text
import Text.Builder qualified
import U.Codebase.Sqlite.DbId (ProjectId)
import U.Codebase.Sqlite.Project qualified
import U.Codebase.Sqlite.ProjectBranch qualified
import Unison.Cli.Monad (Cli)
import Unison.Cli.Monad qualified as Cli
import Unison.Cli.MonadUtils qualified as Cli
@ -66,8 +68,8 @@ handleUpgrade oldName newName = do
Cli.Env {codebase, writeSource} <- ask
(projectAndBranch, _path) <- Cli.expectCurrentProjectBranch
let projectId = projectAndBranch ^. #project . #projectId
let projectPath = Cli.projectBranchPath (ProjectAndBranch projectId (projectAndBranch ^. #branch . #branchId))
let projectId = projectAndBranch.project.projectId
let projectPath = Cli.projectBranchPath (ProjectAndBranch projectId projectAndBranch.branch.branchId)
let oldPath = Path.resolve projectPath (Path.Relative (Path.fromList [NameSegment.libSegment, oldName]))
let newPath = Path.resolve projectPath (Path.Relative (Path.fromList [NameSegment.libSegment, newName]))
@ -160,7 +162,7 @@ handleUpgrade oldName newName = do
temporaryBranchId <-
HandleInput.Branch.doCreateBranch
(HandleInput.Branch.CreateFrom'Branch projectAndBranch)
(projectAndBranch ^. #project)
projectAndBranch.project
temporaryBranchName
textualDescriptionOfUpgrade
let temporaryBranchPath = Path.unabsolute (Cli.projectBranchPath (ProjectAndBranch projectId temporaryBranchId))
@ -170,7 +172,8 @@ handleUpgrade oldName newName = do
Nothing -> "scratch.u"
Just (file, _) -> file
liftIO $ writeSource (Text.pack scratchFilePath) (Text.pack $ Pretty.toPlain 80 prettyUnisonFile)
Cli.returnEarly (Output.UpgradeFailure scratchFilePath oldName newName)
Cli.returnEarly $
Output.UpgradeFailure projectAndBranch.branch.name temporaryBranchName scratchFilePath oldName newName
branchUpdates <-
Cli.runTransactionWithRollback \abort -> do

View File

@ -395,7 +395,7 @@ data Output
| UpdateTypecheckingFailure
| UpdateTypecheckingSuccess
| UpdateIncompleteConstructorSet UpdateOrUpgrade Name (Map ConstructorId Name) (Maybe Int)
| UpgradeFailure !FilePath !NameSegment !NameSegment
| UpgradeFailure !ProjectBranchName !ProjectBranchName !FilePath !NameSegment !NameSegment
| UpgradeSuccess !NameSegment !NameSegment
| LooseCodePushDeprecated
| MergeFailure !FilePath !MergeSourceAndTarget

View File

@ -2256,14 +2256,53 @@ notifyUser dir = \case
<> operationName
<> "again."
]
UpgradeFailure path old new ->
pure . P.wrap $
"I couldn't automatically upgrade"
<> P.text (NameSegment.toEscapedText old)
<> "to"
<> P.group (P.text (NameSegment.toEscapedText new) <> ".")
<> "However, I've added the definitions that need attention to the top of"
<> P.group (prettyFilePath path <> ".")
UpgradeFailure main temp path old new ->
pure $
P.lines
[ P.wrap $
"I couldn't automatically upgrade"
<> P.text (NameSegment.toEscapedText old)
<> "to"
<> P.group (P.text (NameSegment.toEscapedText new) <> ".")
<> "However, I've added the definitions that need attention to the top of"
<> P.group (prettyFilePath path <> "."),
"",
P.wrap "When you're done, you cun run",
"",
P.indentN
2
( P.bulleted
[ IP.makeExampleNoBackticks IP.projectSwitch [prettySlashProjectBranchName main],
IP.makeExampleNoBackticks IP.mergeInputPattern [prettySlashProjectBranchName temp],
IP.makeExampleNoBackticks IP.deleteBranch [prettySlashProjectBranchName temp]
]
),
"",
"or (equivalently)",
"",
P.indentN
2
( P.bulleted
[ IP.makeExampleNoBackticks IP.upgradeCommitInputPattern []
]
),
"",
P.wrap $
"to merge your changes back into"
<> P.group (prettyProjectBranchName main <> ".")
<> "Or, if you'd like to abandon the upgrade instead, you can run",
"",
P.indentN
2
( P.bulleted [IP.makeExampleNoBackticks IP.deleteBranch [prettySlashProjectBranchName temp]]
),
"",
P.wrap $
"to delete"
<> prettyProjectBranchName temp
<> "and switch back to"
<> P.group (prettyProjectBranchName main <> ".")
]
UpgradeSuccess old new ->
pure . P.wrap $
"I upgraded"

View File

@ -35,6 +35,23 @@ proj/main> upgrade old new
I couldn't automatically upgrade old to new. However, I've
added the definitions that need attention to the top of
scratch.u.
When you're done, you cun run
* switch /main
* merge /upgrade-old-to-new
* delete.branch /upgrade-old-to-new
or (equivalently)
* upgrade.commit
to merge your changes back into main. Or, if you'd like to
abandon the upgrade instead, you can run
* delete.branch /upgrade-old-to-new
to delete upgrade-old-to-new and switch back to main.
```
```unison:added-by-ucm scratch.u