diff --git a/assets/jsons/translations/de.json b/assets/jsons/translations/de.json index 9c91e605..1f0b1e8c 100644 --- a/assets/jsons/translations/de.json +++ b/assets/jsons/translations/de.json @@ -441,7 +441,8 @@ "CantEditSteam": "Kann nicht bearbeitet werden", "CantRename": "Umbenennen unmöglich", "VersionAlreadExist": "Diese Version existiert bereits", - "CantClone": "Klonen unmöglich" + "CantClone": "Klonen unmöglich", + "UnknownError": "Ein unbekannter Fehler ist aufgetreten" }, "msg": { "CantEditSteam": "Die Steam-Version kann nicht bearbeitet werden. Du kannst es aber klonen." diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index fcfdaa82..ab105b22 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -448,7 +448,8 @@ "CantEditSteam": "Unable to edit", "CantRename": "Renaming impossible", "VersionAlreadExist": "This version already exists", - "CantClone": "Cloning impossible" + "CantClone": "Cloning impossible", + "UnknownError": "An unknown error occurred" }, "msg": { "CantEditSteam": "You can't edit the Steam version. You can clone it though." diff --git a/assets/jsons/translations/es.json b/assets/jsons/translations/es.json index 9494b412..c49ae715 100644 --- a/assets/jsons/translations/es.json +++ b/assets/jsons/translations/es.json @@ -441,7 +441,8 @@ "CantEditSteam": "Imposible editar", "CantRename": "Cambio de nombre imposible", "VersionAlreadExist": "Esta versión ya existe", - "CantClone": "Clonación imposible" + "CantClone": "Clonación imposible", + "UnknownError": "Ocurrió un error desconocido" }, "msg": { "CantEditSteam": "No puedes editar la versión de Steam. Sin embargo, puedes clonarla." diff --git a/assets/jsons/translations/fr.json b/assets/jsons/translations/fr.json index 2a4c5e14..870e8148 100644 --- a/assets/jsons/translations/fr.json +++ b/assets/jsons/translations/fr.json @@ -441,7 +441,8 @@ "CantEditSteam": "Modification impossible", "CantRename": "Renommage impossible", "VersionAlreadExist": "Cette version existe déjà", - "CantClone": "Clonage impossible" + "CantClone": "Clonage impossible", + "UnknownError": "Une erreur inconnue s'est produite" }, "msg": { "CantEditSteam": "Tu ne peux pas modifier la version Steam, cependant tu peux la cloner." diff --git a/assets/jsons/translations/ja.json b/assets/jsons/translations/ja.json index 5fb10e10..4d0bd4ca 100644 --- a/assets/jsons/translations/ja.json +++ b/assets/jsons/translations/ja.json @@ -441,7 +441,8 @@ "CantEditSteam": "編集不可", "CantRename": "改名不可能", "VersionAlreadExist": "このバージョンは既に存在しています!", - "CantClone": "クローン作成不可" + "CantClone": "クローン作成不可", + "UnknownError": "不明なエラーが発生しました" }, "msg": { "CantEditSteam": "Steam版は編集できませんがクローンを作ることは可能です。" diff --git a/assets/jsons/translations/ru.json b/assets/jsons/translations/ru.json index 4442078a..f8fac1ce 100644 --- a/assets/jsons/translations/ru.json +++ b/assets/jsons/translations/ru.json @@ -441,7 +441,8 @@ "CantEditSteam": "Не удалось изменить", "CantRename": "Переименование невозможно", "VersionAlreadExist": "Эта версия уже добавлена", - "CantClone": "Клонирование невозможно" + "CantClone": "Клонирование невозможно", + "UnknownError": "Произошла неизвестная ошибка" }, "msg": { "CantEditSteam": "Вы не можете изменить версию из Steam, но вы можете её клонировать." diff --git a/assets/jsons/translations/zh-tw.json b/assets/jsons/translations/zh-tw.json index ce36d636..c00f78ae 100644 --- a/assets/jsons/translations/zh-tw.json +++ b/assets/jsons/translations/zh-tw.json @@ -441,7 +441,8 @@ "CantEditSteam": "無法編輯", "CantRename": "無法重命名", "VersionAlreadExist": "該版本已存在", - "CantClone": "無法複製" + "CantClone": "無法複製", + "UnknownError": "發生了未知錯誤" }, "msg": { "CantEditSteam": "你不能編輯 Steam 版本。不過你可以複製它。" diff --git a/assets/jsons/translations/zh.json b/assets/jsons/translations/zh.json index 8be7a687..878150c0 100644 --- a/assets/jsons/translations/zh.json +++ b/assets/jsons/translations/zh.json @@ -441,7 +441,8 @@ "CantEditSteam": "无法编辑", "CantRename": "无法重命名", "VersionAlreadExist": "该版本已存在", - "CantClone": "无法克隆" + "CantClone": "无法克隆", + "UnknownError": "发生了未知错误" }, "msg": { "CantEditSteam": "你不能编辑 Steam 版本。不过你可以克隆它。" diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index 34543bc4..5b8e473e 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -6,14 +6,13 @@ import { BS_APP_ID, OCULUS_BS_BACKUP_DIR, OCULUS_BS_DIR } from "../constants"; import path from "path"; import { ConfigurationService } from "./configuration.service"; import { lstat, rename } from "fs/promises"; -import { BsmException } from "shared/models/bsm-exception.model"; import log from "electron-log"; import { OculusService } from "./oculus.service"; import { DownloadLinkType } from "shared/models/mods"; import sanitize from "sanitize-filename"; import { Progression, copyDirectoryWithJunctions, deleteFolder, ensurePathNotAlreadyExist, getFoldersInFolder, rxCopy } from "../helpers/fs.helpers"; import { FolderLinkerService } from "./folder-linker.service"; -import { ReadStream, createReadStream, pathExists, readFile, writeFile } from "fs-extra"; +import { ReadStream, createReadStream, pathExists, pathExistsSync, readFile, writeFile } from "fs-extra"; import readline from "readline"; import { Observable, Subject, catchError, finalize, from, map, switchMap, throwError } from "rxjs"; import { BsStore } from "../../shared/models/bs-store.enum"; @@ -306,54 +305,58 @@ export class BSLocalVersionService { .catch(() => { return false; }) } - public async editVersion(version: BSVersion, name: string, color: string): Promise{ - if(version.steam || version.oculus){ throw {title: "CantEditSteam", message: "CantEditSteam"} as BsmException; } - const oldPath = await this.getVersionPath(version); - const editedVersion: BSVersion = version.BSVersion === name - ? {...version, name: undefined, color} - : {...version, name: sanitize(name), color}; - const newPath = await this.getVersionPath(editedVersion); + public async editVersion(version: BSVersion, name: string, color: string): Promise{ + if(version.steam || version.oculus){ throw new CustomError("Do not edit official Beat Saber versions", "CantEditSteam") } + const oldPath = await this.getVersionPath(version); + const editedVersion: BSVersion = version.BSVersion === name + ? {...version, name: undefined, color} + : {...version, name: sanitize(name), color}; + const newPath = await this.getVersionPath(editedVersion); - if(oldPath === newPath){ - this.deleteCustomVersion(version); - this.addCustomVersion(editedVersion); - return editedVersion; - } + if(oldPath === newPath){ + this.deleteCustomVersion(version); + this.addCustomVersion(editedVersion); + return editedVersion; + } - if((await pathExists(newPath)) && newPath === oldPath){ throw {title: "VersionAlreadExist"} as BsmException; } + if(pathExistsSync(newPath)){ + throw new CustomError("Unable to edit the version, path already exist", "VersionAlreadExist"); + } - return rename(oldPath, newPath).then(() => { - this.deleteCustomVersion(version); - this.addCustomVersion(editedVersion); - return editedVersion; - }).catch((err: Error) => { - log.error("edit version error", err, version, name, color); - throw {title: "CantRename", ...err} as BsmException; - }); - } + return rename(oldPath, newPath).then(() => { + this.deleteCustomVersion(version); + this.addCustomVersion(editedVersion); + return editedVersion; + }).catch((err: Error) => { + log.error("edit version error", err, version, name, color); + throw CustomError.fromError(err, "CantRename"); + }); + } - public async cloneVersion(version: BSVersion, name: string, color: string): Promise{ - const originPath = await this.getVersionPath(version); - const cloneVersion: BSVersion = version.BSVersion === name - ? {...version, name: undefined, color, steam: false, oculus: false} - : {...version, name: sanitize(name), color, steam: false, oculus: false}; - const newPath = await this.getVersionPath(cloneVersion); + public async cloneVersion(version: BSVersion, name: string, color: string): Promise{ + const originPath = await this.getVersionPath(version); + const cloneVersion: BSVersion = version.BSVersion === name + ? {...version, name: undefined, color, steam: false, oculus: false} + : {...version, name: sanitize(name), color, steam: false, oculus: false}; + const newPath = await this.getVersionPath(cloneVersion); - if(originPath === newPath){ - this.deleteCustomVersion(version); - this.addCustomVersion(cloneVersion); - } + if(pathExistsSync(newPath)){ + throw new CustomError("Unable to clone the version, path already exist", "VersionAlreadExist"); + } - if(await pathExists(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; } + if(originPath === newPath){ + this.deleteCustomVersion(version); + this.addCustomVersion(cloneVersion); + } - return copyDirectoryWithJunctions(originPath, newPath).then(() => { - this.addCustomVersion(cloneVersion); - return cloneVersion; - }).catch((err: Error) => { - log.error("clone version error", err, version, name, color); - throw {title: "CantClone", ...err} as BsmException - }) - } + return copyDirectoryWithJunctions(originPath, newPath).then(() => { + this.addCustomVersion(cloneVersion); + return cloneVersion; + }).catch((err: Error) => { + log.error("Error occured while cloning the version", err, version, name, color); + throw CustomError.fromError(err, "CantClone"); + }) + } public importVersion(opt: ImportVersionOptions): Observable>{ const { fromPath, store } = opt; diff --git a/src/main/services/ipc.service.ts b/src/main/services/ipc.service.ts index 786be0f7..751a9118 100644 --- a/src/main/services/ipc.service.ts +++ b/src/main/services/ipc.service.ts @@ -49,7 +49,7 @@ export class IpcService { const sub = observable.subscribe({ next: data => this.send(channel, window, data), error: error => { - log.error(error, error?.code); + log.error(error, error?.code, error?.data); this.send(this.getErrorChannel(channel), window, serializeError(error)); }, complete: () => this.send(this.getCompleteChannel(channel), window) diff --git a/src/renderer/services/bs-version-manager.service.ts b/src/renderer/services/bs-version-manager.service.ts index d244577f..e9d54bb9 100644 --- a/src/renderer/services/bs-version-manager.service.ts +++ b/src/renderer/services/bs-version-manager.service.ts @@ -8,6 +8,7 @@ import { EditVersionModal } from "renderer/components/modal/modal-types/edit-ver import { popElement } from "shared/helpers/array.helpers"; import { ImportVersionModal } from "renderer/components/modal/modal-types/import-version-modal.component"; import { Progression } from "main/helpers/fs.helpers"; +import { CustomError } from "shared/models/exceptions/custom-error.class"; export class BSVersionManagerService { private static instance: BSVersionManagerService; @@ -77,10 +78,19 @@ export class BSVersionManagerService { this.askInstalledVersions(); return res; }).catch(e => { - this.notification.notifyError({ - title: `notifications.custom-version.errors.titles.${e.error.title}`, - ...(e.error.message && { desc: `notifications.custom-version.errors.msg.${e.error.message}` }), - }); + + const knownErrorTitlesCodes = ["CantEditSteam", "VersionAlreadExist", "CantRename"]; + const knownErrorMessagesCodes = ["CantEditSteam"]; + + if(knownErrorTitlesCodes.includes(e.code)){ + this.notification.notifyError({ + title: `notifications.custom-version.errors.titles.${e.code}`, + desc: knownErrorMessagesCodes.includes(e.code) ? `notifications.custom-version.errors.msg.${e.code}` : null + }); + } else { + this.notification.notifyError({ title: `notifications.custom-version.errors.titles.UnknownError` }); + } + return null; }) } @@ -103,11 +113,16 @@ export class BSVersionManagerService { this.notification.notifySuccess({ title: "notifications.custom-version.success.titles.CloningFinished" }); this.askInstalledVersions(); return res; - }).catch(e => { - this.notification.notifyError({ - title: `notifications.custom-version.errors.titles.${e.error.title}`, - ...(e.error.message && { desc: `notifications.custom-version.errors.msg.${e.error.message}` }), - }); + }).catch((e: CustomError) => { + + const knownErrorTitlesCodes = ["VersionAlreadExist", "CantClone"]; + + if(knownErrorTitlesCodes.includes(e.code)){ + this.notification.notifyError({ title: `notifications.custom-version.errors.titles.${e.code}` }); + } else { + this.notification.notifyError({ title: `notifications.custom-version.errors.titles.UnknownError` }); + } + return null; }).finally(() => { this.progressBar.hide(true)