Small refactoring

This commit is contained in:
kitelev 2025-01-03 22:34:02 +05:00
parent 88e9eb714c
commit d34166eac3
1 changed files with 7 additions and 4 deletions

View File

@ -60,7 +60,7 @@ export default class AppUtils {
return this.getFileByPathOrThrow(areaFileName + ".md"); return this.getFileByPathOrThrow(areaFileName + ".md");
} else { } else {
const areaFileName = strLink.replace("[[", "").replace("]]", ""); const areaFileName = strLink.replace("[[", "").replace("]]", "");
return this.getFileByName(areaFileName + ".md"); return this.getFileByNameOrThrow(areaFileName + ".md");
} }
} }
@ -98,9 +98,12 @@ export default class AppUtils {
return []; return [];
} }
// TODO rename and add `orThrow` getFileByNameOrThrow(parentFileName: string): TFile {
getFileByName(parentFileName: string): TFile { let tFile = this.app.vault.getMarkdownFiles().filter(f => f.name == parentFileName)[0];
return 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 { getFileByPathOrThrow(filePath: string): TFile {