Skip to content

Commit c55fdb1

Browse files
fix: better error handling if changelog path is wrong
1 parent 17e3868 commit c55fdb1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

main.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { App, Plugin, PluginSettingTab, Setting, TFile } from "obsidian";
1+
import {
2+
App,
3+
Notice,
4+
Plugin,
5+
PluginSettingTab,
6+
Setting,
7+
TFile,
8+
} from "obsidian";
29
import type moment from "moment";
310

411
const DEFAULT_SETTINGS: ChangelogSettings = {
@@ -82,9 +89,12 @@ export default class Changelog extends Plugin {
8289
}
8390

8491
async writeInFile(filePath: string, content: string) {
85-
const file = this.app.vault.getAbstractFileByPath(filePath) as TFile;
86-
// TODO: handle errors
87-
await this.app.vault.modify(file, content);
92+
const file = this.app.vault.getAbstractFileByPath(filePath);
93+
if (file instanceof TFile) {
94+
await this.app.vault.modify(file, content);
95+
} else {
96+
new Notice("Couldn't write changelog: check the file path");
97+
}
8898
}
8999

90100
async loadSettings() {

0 commit comments

Comments
 (0)