From f390eca4de6f047bdf03c58db0584d262e9798a2 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 8 May 2023 15:29:07 +0100 Subject: [PATCH] Desktop: Fixes #8143: Fixes crash when using multiple profiles along with certain plugins --- packages/lib/models/Setting.ts | 3 ++- .../mergeGlobalAndLocalSettings.ts | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/lib/models/Setting.ts b/packages/lib/models/Setting.ts index 173f3d0d6..c18b3396d 100644 --- a/packages/lib/models/Setting.ts +++ b/packages/lib/models/Setting.ts @@ -9,6 +9,7 @@ import FileHandler, { SettingValues } from './settings/FileHandler'; import Logger from '../Logger'; import mergeGlobalAndLocalSettings from '../services/profileConfig/mergeGlobalAndLocalSettings'; import splitGlobalAndLocalSettings from '../services/profileConfig/splitGlobalAndLocalSettings'; +import JoplinError from '../JoplinError'; const { sprintf } = require('sprintf-js'); const ObjectUtils = require('../ObjectUtils'); const { toTitleCase } = require('../string-utils.js'); @@ -1810,7 +1811,7 @@ class Setting extends BaseModel { public static settingMetadata(key: string): SettingItem { const metadata = this.metadata(); - if (!(key in metadata)) throw new Error(`Unknown key: ${key}`); + if (!(key in metadata)) throw new JoplinError(`Unknown key: ${key}`, 'unknown_key'); const output = Object.assign({}, metadata[key]); output.key = key; return output; diff --git a/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts b/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts index e5dfacf4c..f296eed8a 100644 --- a/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts +++ b/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts @@ -1,5 +1,8 @@ +import Logger from '../../Logger'; import Setting from '../../models/Setting'; +const logger = Logger.create('mergeGlobalAndLocalSettings'); + export default (rootSettings: Record, subProfileSettings: Record) => { const output: Record = { ...subProfileSettings }; @@ -12,9 +15,20 @@ export default (rootSettings: Record, subProfileSettings: Record