diff --git a/src/lib/option.ts b/src/lib/option.ts index e8af156..c0a3097 100644 --- a/src/lib/option.ts +++ b/src/lib/option.ts @@ -4,6 +4,7 @@ import { ensureDirectory } from './session'; import Variable from 'astal/variable'; import { monitorFile, readFile, writeFile } from 'astal/file'; import GLib from 'gi://GLib?version=2.0'; +import { errorHandler } from './utils'; type OptProps = { persistent?: boolean; @@ -88,8 +89,8 @@ export class Opt extends Variable { if (rawData && rawData.trim() !== '') { try { cacheData = JSON.parse(rawData) as Record; - } catch { - // do nuffin + } catch (error) { + errorHandler(error); } } @@ -178,19 +179,23 @@ export function opt(initial: T, props?: OptProps): Opt { * @returns An array of all found `Opt` instances. */ function getOptions(object: Record, path = '', arr: Opt[] = []): Opt[] { - for (const key in object) { - const value = object[key]; - const id = path ? `${path}.${key}` : key; + try { + for (const key in object) { + const value = object[key]; + const id = path ? `${path}.${key}` : key; - if (value instanceof Variable) { - const optValue = value as Opt; - optValue.id = id; - arr.push(optValue); - } else if (typeof value === 'object' && value !== null) { - getOptions(value as Record, id, arr); + if (value instanceof Variable) { + const optValue = value as Opt; + optValue.id = id; + arr.push(optValue); + } else if (typeof value === 'object' && value !== null) { + getOptions(value as Record, id, arr); + } } + return arr; + } catch (error) { + errorHandler(error); } - return arr; } /** diff --git a/src/lib/session.ts b/src/lib/session.ts index 713c70b..8b89f9f 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -10,7 +10,9 @@ declare global { } export function ensureDirectory(path: string): void { - if (!GLib.file_test(path, GLib.FileTest.EXISTS)) Gio.File.new_for_path(path).make_directory_with_parents(null); + if (!GLib.file_test(path, GLib.FileTest.EXISTS)) { + Gio.File.new_for_path(path).make_directory_with_parents(null); + } } export function ensureFile(path: string): void {