Skip to content

Commit

Permalink
fix: do not use innerHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Oct 2, 2023
1 parent 5559c2f commit 8ae7d5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/utils/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export async function errorWrapper<T>(
export function tryCatch<T>(fn: () => T, msg: string): T | null {
try {
return fn();
} catch (e: any) {
log_error(new ModalFormError(msg, e.message));
} catch (e) {
if (e instanceof Error)
log_error(new ModalFormError(msg, e.message));
return null;
}
}
33 changes: 16 additions & 17 deletions src/utils/Log.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { Notice } from "obsidian";
import { ModalFormError } from "./Error";

export function log_update(msg: string): void {
const notice = new Notice("", 15000);
// TODO: Find better way for this
// @ts-ignore
notice.noticeEl.innerHTML = `<b>Modal form update</b>:<br/>${msg}`;
}

export function log_notice(title: string, msg: string): void {
const notice = new Notice("", 15000);
// TODO: Find better way for this
// @ts-ignore
notice.noticeEl.innerHTML = `<b>${title}</b>:<br/>${msg}`;
const notice = new Notice("", 15000);
const el = notice.noticeEl;
el.empty();
const head = el.createEl('h6', { text: title })
const body = el.createEl('div', { text: title })
el.append(head, body);
}

export function log_update(msg: string): void {
log_notice('Modal form update', msg)
}

export function log_error(e: Error | ModalFormError): void {
const notice = new Notice("", 8000);
if (e instanceof ModalFormError && e.console_msg) {
notice.noticeEl.innerHTML = `<b>Modal form Error</b>:<br/>${e.message}<br/>Check console for more information`;
console.error(`Modal form Error:`, e.message, "\n", e.console_msg);
} else {
notice.noticeEl.innerHTML = `<b>Modal form Error</b>:<br/>${e.message}`;
}
if (e instanceof ModalFormError && e.console_msg) {
log_notice('Modal from error', e.message)
console.error(`Modal form Error:`, e.message, "\n", e.console_msg);
} else {
log_notice('Modal from error', e.message)
}
}

0 comments on commit 8ae7d5b

Please sign in to comment.