Safer failing to load SETTINGS fallback
This commit is contained in:
parent
8b860194d7
commit
9ca1382cf1
@ -2,6 +2,7 @@ import { SETTINGS_TEMPLATE } from "./settings_template.ts";
|
|||||||
import { YAML } from "./deps.ts";
|
import { YAML } from "./deps.ts";
|
||||||
import { SpacePrimitives } from "./spaces/space_primitives.ts";
|
import { SpacePrimitives } from "./spaces/space_primitives.ts";
|
||||||
import { expandPropertyNames } from "$sb/lib/json.ts";
|
import { expandPropertyNames } from "$sb/lib/json.ts";
|
||||||
|
import type { BuiltinSettings } from "../web/types.ts";
|
||||||
|
|
||||||
export function safeRun(fn: () => Promise<void>) {
|
export function safeRun(fn: () => Promise<void>) {
|
||||||
fn().catch((e) => {
|
fn().catch((e) => {
|
||||||
@ -36,7 +37,7 @@ export function parseYamlSettings(settingsMarkdown: string): {
|
|||||||
|
|
||||||
export async function ensureSettingsAndIndex(
|
export async function ensureSettingsAndIndex(
|
||||||
space: SpacePrimitives,
|
space: SpacePrimitives,
|
||||||
): Promise<any> {
|
): Promise<BuiltinSettings> {
|
||||||
let settingsText: string | undefined;
|
let settingsText: string | undefined;
|
||||||
try {
|
try {
|
||||||
settingsText = new TextDecoder().decode(
|
settingsText = new TextDecoder().decode(
|
||||||
@ -52,7 +53,10 @@ export async function ensureSettingsAndIndex(
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.error("Error reading settings", e.message);
|
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;
|
settingsText = SETTINGS_TEMPLATE;
|
||||||
// Ok, then let's also check the index page
|
// 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);
|
expandPropertyNames(settings);
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user