From d34166eac3b25bccb6b5de93e7ee9cfdac87f3c0 Mon Sep 17 00:00:00 2001 From: kitelev Date: Fri, 3 Jan 2025 22:34:02 +0500 Subject: [PATCH] Small refactoring --- app/src/utils/AppUtils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/utils/AppUtils.ts b/app/src/utils/AppUtils.ts index b2b3657..774894a 100644 --- a/app/src/utils/AppUtils.ts +++ b/app/src/utils/AppUtils.ts @@ -60,7 +60,7 @@ export default class AppUtils { return this.getFileByPathOrThrow(areaFileName + ".md"); } else { const areaFileName = strLink.replace("[[", "").replace("]]", ""); - return this.getFileByName(areaFileName + ".md"); + return this.getFileByNameOrThrow(areaFileName + ".md"); } } @@ -98,9 +98,12 @@ export default class AppUtils { return []; } - // TODO rename and add `orThrow` - getFileByName(parentFileName: string): TFile { - return this.app.vault.getMarkdownFiles().filter(f => f.name == parentFileName)[0]; + getFileByNameOrThrow(parentFileName: string): TFile { + let tFile = this.app.vault.getMarkdownFiles().filter(f => f.name == parentFileName)[0]; + if (!tFile) { + throw new Error("File not found by name " + parentFileName); + } + return tFile; } getFileByPathOrThrow(filePath: string): TFile {