Skip to content

Fail when Swift installation fails#2080

Open
thePianoKid wants to merge 24 commits intoswiftlang:mainfrom
thePianoKid:incorrect-toolchain-handling
Open

Fail when Swift installation fails#2080
thePianoKid wants to merge 24 commits intoswiftlang:mainfrom
thePianoKid:incorrect-toolchain-handling

Conversation

@thePianoKid
Copy link
Contributor

Description

Currently, the Swiftly installation flow doesn't know if the Swift install failed — it prompts the user to restart their editor as if nothing happened:

image

This PR checks if any of the installations failed. If any installation failed, a popup is rendered telling the user to check their Swift version in .swift-version.

Issue: #2070

Tasks

  • Required tests have been written
  • Manual tests:
    • macOS:
      • Included a wrong Swift version number in .swift-version, and confirmed that the "restart VS Code" modal was replaced by the "installation failed" modal.
      • Included a correct Swift version number in .swift-version, and made sure the "restart VS Code" model was still rendered.
  • Documentation has been updated
  • Added an entry to CHANGELOG.md if applicable


// Install toolchains
const swiftlyPath = path.join(Swiftly.defaultHomeDir(), "bin/swiftly");
let installSuccess = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should validate that the versions array is not empty, otherwise installSuccess will report true without installing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is nothing to install, we still want to prompt the user the restart, and return true. Which is what happens currently:

let installSuccess = true;
    for (const version of swiftVersions) {
        installSuccess =
            installSuccess &&
            (await installSwiftlyToolchainWithProgress(
                version,
                extensionRoot,
                logger,
                swiftlyPath
            ));
    }

    // The for loop is skipped, and the user is prompted to restart
    if (installSuccess) {
        await promptToRestartVSCode();
        return true;
    } 

The issue seems to a bad variable name: promptRestart might be better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking on the original implementation: I think we should, at the very least, install the latest toolchain if no toolchain versions are provided. That's the whole point of installing swiftly, after all.

Thankfully, swiftly makes this easy by letting us do swiftly install latest. So, we can just add "latest" if the array is empty.

await promptToRestartVSCode();
return true;
} else {
await vscode.window.showErrorMessage("Installation failed", {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we get any error message from the installation failure? It would be useful to show the failure message from the install to help the user diagnose why it failed.

@thePianoKid
Copy link
Contributor Author

I merged the code from #2078 to this PR to avoid code duplication. That means that #2078 should be merged before this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants