From 9ca1382cf1c46358326e3869722e62228d2235e3 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 18 Dec 2023 16:54:55 +0100 Subject: [PATCH] Safer failing to load SETTINGS fallback --- common/util.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/util.ts b/common/util.ts index aefe5f86..3c51215a 100644 --- a/common/util.ts +++ b/common/util.ts @@ -2,6 +2,7 @@ import { SETTINGS_TEMPLATE } from "./settings_template.ts"; import { YAML } from "./deps.ts"; import { SpacePrimitives } from "./spaces/space_primitives.ts"; import { expandPropertyNames } from "$sb/lib/json.ts"; +import type { BuiltinSettings } from "../web/types.ts"; export function safeRun(fn: () => Promise) { fn().catch((e) => { @@ -36,7 +37,7 @@ export function parseYamlSettings(settingsMarkdown: string): { export async function ensureSettingsAndIndex( space: SpacePrimitives, -): Promise { +): Promise { let settingsText: string | undefined; try { settingsText = new TextDecoder().decode( @@ -52,7 +53,10 @@ export async function ensureSettingsAndIndex( ); } else { console.error("Error reading settings", e.message); - console.error("Falling back to default settings"); + console.warn("Falling back to default settings"); + return { + indexPage: "index", + }; } settingsText = SETTINGS_TEMPLATE; // Ok, then let's also check the index page @@ -77,7 +81,7 @@ page: "[[!silverbullet.md/Getting Started]]" } } - const settings = parseYamlSettings(settingsText); + const settings: any = parseYamlSettings(settingsText); expandPropertyNames(settings); return settings; }