Skip to content

Commit 8a8b61c

Browse files
committed
[CODE-102] Add check if cask could not install properly
1 parent 19b4da9 commit 8a8b61c

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/resources/homebrew/casks-parameter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export class CasksParameter extends ArrayStatefulParameter<HomebrewConfig, strin
6363
const result = await codifySpawn(`SUDO_ASKPASS=${SUDO_ASKPASS_PATH} brew install --casks ${casks.join(' ')}`)
6464

6565
if (result.status === SpawnStatus.SUCCESS) {
66+
67+
// Casks can't detect if a program was installed by other means. If it returns this message, throw an error
68+
if (result.data.includes('It seems there is already an App at')) {
69+
throw new Error(`A program already exists for cask ${casks}`)
70+
}
71+
6672
console.log(`Installed casks: ${casks.join(' ')}`);
6773
} else {
6874
throw new Error(`Failed to install casks: ${casks}. ${JSON.stringify(result.data, null, 2)}`)

src/resources/homebrew/homebrew.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ export class HomebrewResource extends Resource<HomebrewConfig> {
3636
});
3737
}
3838

39-
async onInitialize(): Promise<void> {
40-
await this.saveSudoAskpassIfNotExists();
41-
}
42-
4339
async refresh(parameters: Partial<HomebrewConfig>): Promise<Partial<HomebrewConfig> | null> {
4440
const homebrewInfo = await codifySpawn('brew config', { throws: false });
4541
if (homebrewInfo.status === SpawnStatus.ERROR) {
@@ -55,6 +51,8 @@ export class HomebrewResource extends Resource<HomebrewConfig> {
5551
}
5652

5753
async applyCreate(plan: CreatePlan<HomebrewConfig>): Promise<void> {
54+
await this.saveSudoAskpassIfNotExists();
55+
5856
if (plan.desiredConfig.directory) {
5957
return this.installBrewInCustomDir(plan.desiredConfig.directory)
6058
}

0 commit comments

Comments
 (0)