Skip to content

Commit

Permalink
Throw errors from installModAfterDownload instead of returning them
Browse files Browse the repository at this point in the history
  • Loading branch information
VilppeRiskidev committed Sep 30, 2024
1 parent 0ea5e3a commit 7bc0283
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,20 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
if (!keepIterating) {
return;
}
const installResult: R2Error | ManifestV2 = await ProfileUtils.installModAfterDownload(comboMod.getMod(), comboMod.getVersion(), this.activeProfile);
if (installResult instanceof R2Error) {
this.$store.commit('error/handleError', installResult);
let installedMod: ManifestV2;
try {
installedMod = await ProfileUtils.installModAfterDownload(comboMod.getMod(), comboMod.getVersion(), this.activeProfile);
} catch (e) {
this.$store.commit('error/handleError', e);
keepIterating = false;
this.isProfileBeingImported = false;
return;
}
for (const imported of modList) {
if (imported.getName() == comboMod.getMod().getFullName() && !imported.isEnabled()) {
await ProfileModList.updateMod(installResult, this.activeProfile, async (modToDisable: ManifestV2) => {
await ProfileModList.updateMod(installedMod, this.activeProfile, async (modToDisable: ManifestV2) => {
// Need to enable temporarily so the manager doesn't think it's re-disabling a disabled mod.
modToDisable.enable();
await ProfileInstallerProvider.instance.disableMod(modToDisable, this.activeProfile);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/ProfileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ export async function extractZippedProfileFile(file: string, profileName: string
}
}

export async function installModAfterDownload(mod: ThunderstoreMod, version: ThunderstoreVersion, profile: Profile): Promise<R2Error | ManifestV2> {
export async function installModAfterDownload(mod: ThunderstoreMod, version: ThunderstoreVersion, profile: Profile): Promise<ManifestV2> {
const manifestMod: ManifestV2 = new ManifestV2().fromThunderstoreMod(mod, version);
const installError: R2Error | null = await ProfileInstallerProvider.instance.installMod(manifestMod, profile);
if (installError instanceof R2Error) {
return installError;
throw installError;
}

const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile);
if (newModList instanceof R2Error) {
return newModList;
throw newModList;
}

return manifestMod;
Expand Down

0 comments on commit 7bc0283

Please sign in to comment.