From 8567b8aa98b190b810038f8293f0bb51ca2f8792 Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Sat, 4 Nov 2023 01:04:07 +0100 Subject: [PATCH] chore: remove unused code --- src/API.ts | 2 +- src/core/FormResult.ts | 2 +- src/main.ts | 2 +- src/suggesters/SafeDataviewQuery.ts | 2 +- src/utils/Error.ts | 45 ----------------------------- src/utils/Log.ts | 2 +- src/utils/ModalFormError.ts | 7 +++++ src/views/FormBuilder.svelte | 2 +- 8 files changed, 13 insertions(+), 51 deletions(-) delete mode 100644 src/utils/Error.ts create mode 100644 src/utils/ModalFormError.ts diff --git a/src/API.ts b/src/API.ts index 72fc329f..d047484e 100644 --- a/src/API.ts +++ b/src/API.ts @@ -5,7 +5,7 @@ import { MigrationError } from "./core/formDefinitionSchema"; import FormResult from "./core/FormResult"; import { exampleModalDefinition } from "./exampleModalDefinition"; import ModalFormPlugin from "./main"; -import { ModalFormError } from "./utils/Error"; +import { ModalFormError } from "./utils/ModalFormError"; import { FormModal } from "./FormModal"; import { log_error, log_notice } from "./utils/Log"; diff --git a/src/core/FormResult.ts b/src/core/FormResult.ts index 7cb4d54b..9c08c233 100644 --- a/src/core/FormResult.ts +++ b/src/core/FormResult.ts @@ -1,7 +1,7 @@ import { objectSelect } from './objectSelect'; import { stringifyYaml } from "obsidian"; import { log_error } from "../utils/Log"; -import { ModalFormError } from "../utils/Error"; +import { ModalFormError } from "../utils/ModalFormError"; type ResultStatus = "ok" | "cancelled"; diff --git a/src/main.ts b/src/main.ts index f0b2f9dc..cea8baa7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,7 @@ import { ModalFormSettingTab } from "src/ModalFormSettingTab"; import { API } from "src/API"; import { EDIT_FORM_VIEW, EditFormView } from "src/views/EditFormView"; import { MANAGE_FORMS_VIEW, ManageFormsView } from "src/views/ManageFormsView"; -import { ModalFormError } from "src/utils/Error"; +import { ModalFormError } from "src/utils/ModalFormError"; import { type FormDefinition } from "src/core/formDefinition"; import { formNeedsMigration, migrateToLatest, MigrationError, InvalidData } from "./core/formDefinitionSchema"; import { parseSettings, type ModalFormSettings, type OpenPosition, getDefaultSettings } from "src/core/settings"; diff --git a/src/suggesters/SafeDataviewQuery.ts b/src/suggesters/SafeDataviewQuery.ts index 220a860b..3ed5ff2e 100644 --- a/src/suggesters/SafeDataviewQuery.ts +++ b/src/suggesters/SafeDataviewQuery.ts @@ -1,7 +1,7 @@ import { E, Either, flow } from "@std"; import { pipe } from "fp-ts/lib/function"; import { App } from "obsidian"; -import { ModalFormError } from "src/utils/Error"; +import { ModalFormError } from "src/utils/ModalFormError"; import { log_error } from "src/utils/Log"; type DataviewQuery = (dv: unknown, pages: unknown) => unknown; diff --git a/src/utils/Error.ts b/src/utils/Error.ts deleted file mode 100644 index e98b84d8..00000000 --- a/src/utils/Error.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { log_error } from "./Log"; - -export class ModalFormError extends Error { - constructor(msg: string, public console_msg?: string) { - super(msg); - this.name = this.constructor.name; - Error.captureStackTrace(this, this.constructor); - } -} - -export async function errorWrapper( - fn: () => Promise, - msg: string -): Promise { - try { - return await fn(); - } catch (e) { - const err = e instanceof Error ? e : new Error(String(e)); - if (!(err instanceof ModalFormError)) { - log_error(new ModalFormError(msg, err.message)); - } else { - log_error(err); - } - return null; - } -} - -/** - * I case of error, logs it to the console and to the UI - * and returns null - * @export - * @template T - * @param {() => T} fn - * @param {string} msg - * @return {*} {(T | null)} - */ -export function tryCatch(fn: () => T, msg: string): T | null { - try { - return fn(); - } catch (e) { - if (e instanceof Error) - log_error(new ModalFormError(msg, e.message)); - return null; - } -} diff --git a/src/utils/Log.ts b/src/utils/Log.ts index 6396aeca..b4e4b876 100644 --- a/src/utils/Log.ts +++ b/src/utils/Log.ts @@ -1,5 +1,5 @@ import { Notice } from "obsidian"; -import { ModalFormError } from "./Error"; +import { ModalFormError } from "./ModalFormError"; export function log_notice(title: string, msg: string | DocumentFragment): void { diff --git a/src/utils/ModalFormError.ts b/src/utils/ModalFormError.ts new file mode 100644 index 00000000..70112152 --- /dev/null +++ b/src/utils/ModalFormError.ts @@ -0,0 +1,7 @@ +export class ModalFormError extends Error { + constructor(msg: string, public console_msg?: string) { + super(msg); + this.name = this.constructor.name; + Error.captureStackTrace(this, this.constructor); + } +} diff --git a/src/views/FormBuilder.svelte b/src/views/FormBuilder.svelte index 5bd1f603..f54bf4d5 100644 --- a/src/views/FormBuilder.svelte +++ b/src/views/FormBuilder.svelte @@ -11,7 +11,7 @@ import InputBuilderSelect from "./components/InputBuilderSelect.svelte"; import InputFolder from "./components/InputFolder.svelte"; import { log_error } from "src/utils/Log"; - import { ModalFormError } from "src/utils/Error"; + import { ModalFormError } from "src/utils/ModalFormError"; export let definition: EditableFormDefinition = { title: "",