From 803c3a3d3453d1b30c10870389e473e33b52ded9 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 6 Jul 2021 10:16:04 -0400 Subject: [PATCH] Unblock subsequent Singleton.createInstance() (#3225) - Also fix clusters with unknown workspaces Signed-off-by: Sebastian Malton --- src/common/utils/singleton.ts | 11 +++++++---- src/migrations/helpers.ts | 4 +++- src/migrations/hotbar-store/5.0.0-beta.10.ts | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common/utils/singleton.ts b/src/common/utils/singleton.ts index 6b53a19537..ca8eb3eb61 100644 --- a/src/common/utils/singleton.ts +++ b/src/common/utils/singleton.ts @@ -46,12 +46,15 @@ export class Singleton { static createInstance(this: StaticThis, ...args: R): T { if (!Singleton.instances.has(this)) { if (Singleton.creating.length > 0) { - throw new TypeError("Cannot create a second singleton while creating a first"); + throw new TypeError(`Cannot create a second singleton (${this.name}) while creating a first (${Singleton.creating})`); } - Singleton.creating = this.name; - Singleton.instances.set(this, new this(...args)); - Singleton.creating = ""; + try { + Singleton.creating = this.name; + Singleton.instances.set(this, new this(...args)); + } finally { + Singleton.creating = ""; + } } return Singleton.instances.get(this) as T; diff --git a/src/migrations/helpers.ts b/src/migrations/helpers.ts index 623d46a63e..8ed4242652 100644 --- a/src/migrations/helpers.ts +++ b/src/migrations/helpers.ts @@ -44,8 +44,10 @@ export function joinMigrations(...declarations: MigrationDeclaration[]): Migrati return Object.fromEntries( iter.map( - migrations, + migrations, ([v, fns]) => [v, (store: Conf) => { + migrationLog(`Running ${v} migration for ${store.path}`); + for (const fn of fns) { fn(store); } diff --git a/src/migrations/hotbar-store/5.0.0-beta.10.ts b/src/migrations/hotbar-store/5.0.0-beta.10.ts index 9a696ba36c..af6af5370c 100644 --- a/src/migrations/hotbar-store/5.0.0-beta.10.ts +++ b/src/migrations/hotbar-store/5.0.0-beta.10.ts @@ -75,6 +75,11 @@ export default { for (const workspaceId of cluster.workspaces ?? [cluster.workspace].filter(Boolean)) { const workspaceHotbar = workspaceHotbars.get(workspaceId); + if (!workspaceHotbar) { + migrationLog(`Cluster ${uid} has unknown workspace ID, skipping`); + continue; + } + migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`); if (workspaceHotbar?.items.length < defaultHotbarCells) {