From 60f6414d5af7936b2293f676f0c6060fc33f6f15 Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Thu, 3 Oct 2024 13:32:16 +0200 Subject: [PATCH 1/4] Initialize tag variable before use in nested function call. --- packages/service-core/src/api/diagnostics.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/service-core/src/api/diagnostics.ts b/packages/service-core/src/api/diagnostics.ts index 7b6da99ce..eca98da9b 100644 --- a/packages/service-core/src/api/diagnostics.ts +++ b/packages/service-core/src/api/diagnostics.ts @@ -53,6 +53,8 @@ export async function getSyncRulesStatus( }; } + const sourceConfig = await apiHandler.getSourceConfig(); + const tag = sourceConfig.tag ?? DEFAULT_TAG; const systemStorage = live_status ? bucketStorage.getInstance(sync_rules) : undefined; const status = await systemStorage?.getStatus(); let replication_lag_bytes: number | undefined = undefined; @@ -128,15 +130,12 @@ export async function getSyncRulesStatus( }) ); - const sourceConfig = await apiHandler.getSourceConfig(); - const tag = sourceConfig.tag ?? DEFAULT_TAG; - return { content: include_content ? sync_rules.sync_rules_content : undefined, connections: [ { id: sourceConfig.id ?? DEFAULT_DATASOURCE_ID, - tag: sourceConfig.tag ?? DEFAULT_TAG, + tag: tag, slot_name: sync_rules.slot_name, initial_replication_done: status?.snapshot_done ?? false, // TODO: Rename? From 04937a81adcabefeee73f40153f64cd0363ce35a Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Thu, 3 Oct 2024 14:17:12 +0200 Subject: [PATCH 2/4] Add comment for tag default value --- packages/service-core/src/api/diagnostics.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/service-core/src/api/diagnostics.ts b/packages/service-core/src/api/diagnostics.ts index eca98da9b..387ed4dff 100644 --- a/packages/service-core/src/api/diagnostics.ts +++ b/packages/service-core/src/api/diagnostics.ts @@ -54,6 +54,10 @@ export async function getSyncRulesStatus( } const sourceConfig = await apiHandler.getSourceConfig(); + // This is a bit weird. + // This method can run under some situations if no connection is configured. + // It will return a default tag if no connection is available. This default tag + // is not module specific. const tag = sourceConfig.tag ?? DEFAULT_TAG; const systemStorage = live_status ? bucketStorage.getInstance(sync_rules) : undefined; const status = await systemStorage?.getStatus(); From e4d19b2fd142badf589e712b3368afc5bcce1c14 Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Thu, 3 Oct 2024 15:16:21 +0200 Subject: [PATCH 3/4] Changeset --- .changeset/olive-spoons-stare.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/olive-spoons-stare.md diff --git a/.changeset/olive-spoons-stare.md b/.changeset/olive-spoons-stare.md new file mode 100644 index 000000000..df58ecaf4 --- /dev/null +++ b/.changeset/olive-spoons-stare.md @@ -0,0 +1,5 @@ +--- +'@powersync/service-core': patch +--- + +Moved tag variable initialization in diagnostics route to ensure it is initialized before usage From b8dfc98b0d575dd582b9bdf2c73a7273b7c4aad2 Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Thu, 3 Oct 2024 15:44:38 +0200 Subject: [PATCH 4/4] Comment update --- packages/service-core/src/api/diagnostics.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/service-core/src/api/diagnostics.ts b/packages/service-core/src/api/diagnostics.ts index 387ed4dff..2ebf5ada5 100644 --- a/packages/service-core/src/api/diagnostics.ts +++ b/packages/service-core/src/api/diagnostics.ts @@ -54,10 +54,8 @@ export async function getSyncRulesStatus( } const sourceConfig = await apiHandler.getSourceConfig(); - // This is a bit weird. - // This method can run under some situations if no connection is configured. - // It will return a default tag if no connection is available. This default tag - // is not module specific. + // This method can run under some situations if no connection is configured yet. + // It will return a default tag in such a case. This default tag is not module specific. const tag = sourceConfig.tag ?? DEFAULT_TAG; const systemStorage = live_status ? bucketStorage.getInstance(sync_rules) : undefined; const status = await systemStorage?.getStatus();