diff --git a/src/core/settings.ts b/src/core/settings.ts index 54829ca1..96ce8b0b 100644 --- a/src/core/settings.ts +++ b/src/core/settings.ts @@ -27,12 +27,13 @@ const ModalFormSettingsSchema = object({ type ModalFormSettingsPartial = Output; -const DEFAULT_SETTINGS: ModalFormSettings = { +export const DEFAULT_SETTINGS: ModalFormSettings = { editorPosition: 'right', formDefinitions: [], }; + export function parseSettings(maybeSettings: unknown): E.Either { - if (maybeSettings === null) return E.right(DEFAULT_SETTINGS) + if (maybeSettings === null) return E.right({ ...DEFAULT_SETTINGS }) ; return E.tryCatch(() => parse(ModalFormSettingsSchema, { ...DEFAULT_SETTINGS, ...maybeSettings }), e => e as ValiError); } diff --git a/src/main.ts b/src/main.ts index d8551a82..aa15c9a9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ 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 { formNeedsMigration, type FormDefinition, migrateToLatest } from "src/core/formDefinition"; -import { parseSettings, type ModalFormSettings, type OpenPosition } from "src/core/settings"; +import { parseSettings, type ModalFormSettings, type OpenPosition, DEFAULT_SETTINGS } from "src/core/settings"; import { log_error, log_notice } from "./utils/Log"; import * as E from "fp-ts/Either"; import { pipe } from "fp-ts/function"; @@ -125,9 +125,9 @@ export default class ModalFormPlugin extends Plugin { const data = await this.loadData(); const settingsParsed = parseSettings(data); if (E.isLeft(settingsParsed)) { - const error = new ModalFormError('Settings are not valid, check the errors', JSON.stringify(settingsParsed.left.issues)) + const error = new ModalFormError('Settings are not valid, check the errors', JSON.stringify(settingsParsed.left.issues, null, 2)) log_error(error) - throw error; + return { ...DEFAULT_SETTINGS }; } const settings = settingsParsed.right; const migrationIsNeeded = settings.formDefinitions.some(formNeedsMigration); diff --git a/src/utils/Log.ts b/src/utils/Log.ts index f5a3d4b9..6396aeca 100644 --- a/src/utils/Log.ts +++ b/src/utils/Log.ts @@ -17,7 +17,7 @@ export function log_update(msg: string): void { export function log_error(e: Error | ModalFormError): void { if (e instanceof ModalFormError && e.console_msg) { - log_notice('Modal from error', e.message) + log_notice('Modal from error: ', e.message + "\n" + e.console_msg) console.error(`Modal form Error:`, e.message, "\n", e.console_msg); } else { log_notice('Modal from error', e.message)