From d9694d868ef31892093477a6278265737fbcb7ae Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Sat, 14 Sep 2024 20:38:23 +0800 Subject: [PATCH] try to fix unknown error --- src/main/config/app.ts | 1 + src/main/config/controledMihomo.ts | 2 ++ src/main/config/override.ts | 3 ++- src/main/config/profile.ts | 7 +++++-- src/main/core/factory.ts | 3 ++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/config/app.ts b/src/main/config/app.ts index ad25f3a..64fdc00 100644 --- a/src/main/config/app.ts +++ b/src/main/config/app.ts @@ -11,6 +11,7 @@ export async function getAppConfig(force = false): Promise { const data = await readFile(appConfigPath(), 'utf-8') appConfig = yaml.parse(data) || defaultConfig } + if (typeof appConfig !== 'object') appConfig = defaultConfig return appConfig } diff --git a/src/main/config/controledMihomo.ts b/src/main/config/controledMihomo.ts index fba9e92..e5b7f37 100644 --- a/src/main/config/controledMihomo.ts +++ b/src/main/config/controledMihomo.ts @@ -14,6 +14,8 @@ export async function getControledMihomoConfig(force = false): Promise { if (force || !overrideConfig) { const data = await readFile(overrideConfigPath(), 'utf-8') - overrideConfig = yaml.parse(data) || {} + overrideConfig = yaml.parse(data) || { items: [] } } + if (typeof overrideConfig !== 'object') overrideConfig = { items: [] } return overrideConfig } diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 262bc3a..a9f8e8a 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -14,8 +14,9 @@ let profileConfig: IProfileConfig // profile.yaml export async function getProfileConfig(force = false): Promise { if (force || !profileConfig) { const data = await readFile(profileConfigPath(), 'utf-8') - profileConfig = yaml.parse(data) + profileConfig = yaml.parse(data) || { items: [] } } + if (typeof profileConfig !== 'object') profileConfig = { items: [] } return profileConfig } @@ -168,7 +169,9 @@ export async function setProfileStr(id: string, content: string): Promise export async function getProfile(id: string | undefined): Promise { const profile = await getProfileStr(id) - return yaml.parse(profile) || {} + let result = yaml.parse(profile) || {} + if (typeof result !== 'object') result = {} + return result } // attachment;filename=xxx.yaml; filename*=UTF-8''%xx%xx%xx diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index 5901a81..d0fc5a2 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -44,7 +44,8 @@ async function overrideProfile( profile = runOverrideScript(profile, content, item) break case 'yaml': { - const patch = yaml.parse(content) || {} + let patch = yaml.parse(content) || {} + if (typeof patch !== 'object') patch = {} profile = deepMerge(profile, patch) break }