diff --git a/localization/locales/en/translation.json b/localization/locales/en/translation.json index e61c4ce4..a7834f2f 100644 --- a/localization/locales/en/translation.json +++ b/localization/locales/en/translation.json @@ -252,7 +252,9 @@ "InitWikiGitError": "InitWikiGitError", "InitWikiGitErrorDescription": "The template used by the new note repository failed to copy or the git initialization of the note repository failed. This should be a bug.", "InitWikiGitRevertError": "InitWikiGitRevertError", - "InitWikiGitRevertErrorDescription": "Not only did the initialization of the note warehouse fail, but also the revocation failed. This is a serious problem, and you need to manually clean up the new folder generated in this location." + "InitWikiGitRevertErrorDescription": "Not only did the initialization of the note warehouse fail, but also the revocation failed. This is a serious problem, and you need to manually clean up the new folder generated in this location.", + "CopyWikiTemplateError": "CopyWikiTemplateError", + "CopyWikiTemplateErrorDescription": "Attempt to copy or overwrite the latest wiki template to the corresponding location, but failed. This should be caused by a bug." }, "Loading": "Loading", "Yes": "Yes", diff --git a/localization/locales/zh_CN/translation.json b/localization/locales/zh_CN/translation.json index d933b83d..e0afc7a7 100644 --- a/localization/locales/zh_CN/translation.json +++ b/localization/locales/zh_CN/translation.json @@ -253,7 +253,9 @@ "InitWikiGitError": "笔记仓库初始化失败错误", "InitWikiGitErrorDescription": "新笔记仓库所用的模板复制失败或者笔记仓库的git初始化失败,这应该是个bug。", "InitWikiGitRevertError": "笔记仓库初始化失败且撤销失败错误", - "InitWikiGitRevertErrorDescription": "不仅笔记仓库初始化失败了,而且撤销也失败了,这是个严重问题,需要你手动清理该位置生成的新文件夹。" + "InitWikiGitRevertErrorDescription": "不仅笔记仓库初始化失败了,而且撤销也失败了,这是个严重问题,需要你手动清理该位置生成的新文件夹。", + "CopyWikiTemplateError": "复制维基模板错误", + "CopyWikiTemplateErrorDescription": "尝试把最新维基模板复制或覆盖到对应位置,但是失败了,这应该是由bug导致的。" }, "Loading": "加载中", "Yes": "是的", diff --git a/src/services/wiki/error.ts b/src/services/wiki/error.ts new file mode 100644 index 00000000..b65067cd --- /dev/null +++ b/src/services/wiki/error.ts @@ -0,0 +1,9 @@ +import i18n from '@services/libs/i18n'; + +export class CopyWikiTemplateError extends Error { + constructor(extraMessage?: string) { + super(extraMessage); + this.name = i18n.t('Error.CopyWikiTemplateError'); + this.message = `${i18n.t('Error.CopyWikiTemplateErrorDescription')} ${extraMessage ?? ''}`; + } +} diff --git a/src/services/wiki/index.ts b/src/services/wiki/index.ts index b859b0f1..dd6691e7 100644 --- a/src/services/wiki/index.ts +++ b/src/services/wiki/index.ts @@ -26,6 +26,7 @@ import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/path import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './update-plugin-content'; import { IWikiService } from './interface'; import { WikiChannel } from '@/constants/channels'; +import { CopyWikiTemplateError } from './error'; @injectable() export class Wiki implements IWikiService { @@ -55,12 +56,11 @@ export class Wiki implements IWikiService { } // handlers - public async copyWikiTemplate(newFolderPath: string, folderName: string): Promise { + public async copyWikiTemplate(newFolderPath: string, folderName: string): Promise { try { await this.createWiki(newFolderPath, folderName); - return ''; } catch (error) { - return (error as Error).message; + throw new CopyWikiTemplateError((error as Error).message); } } diff --git a/src/services/wiki/interface.ts b/src/services/wiki/interface.ts index d36da146..0589041b 100644 --- a/src/services/wiki/interface.ts +++ b/src/services/wiki/interface.ts @@ -12,7 +12,7 @@ export interface IWikiService { startWiki(homePath: string, tiddlyWikiPort: number, userName: string): Promise; stopWiki(homePath: string): Promise; stopAllWiki(): Promise; - copyWikiTemplate(newFolderPath: string, folderName: string): Promise; + copyWikiTemplate(newFolderPath: string, folderName: string): Promise; getSubWikiPluginContent(mainWikiPath: string): Promise; /** send tiddlywiki action message to current active wiki */ requestWikiSendActionMessage(actionMessage: string): Promise;