From 606cde60d1238ca070a9e039bdb8833747ee1bdb Mon Sep 17 00:00:00 2001 From: HeinrichvonStein <96476812+HeinrichvonStein@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:02:21 +0200 Subject: [PATCH 1/2] Handle typo in powersync_url env variable --- .changeset/fuzzy-bears-nail.md | 6 ++++++ packages/common/src/client/sync/stream/AbstractRemote.ts | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/fuzzy-bears-nail.md diff --git a/.changeset/fuzzy-bears-nail.md b/.changeset/fuzzy-bears-nail.md new file mode 100644 index 000000000..63ed407a4 --- /dev/null +++ b/.changeset/fuzzy-bears-nail.md @@ -0,0 +1,6 @@ +--- +'@powersync/common': patch +'@powersync/web': patch +--- + +Handle additional forward slash in the POWERSYNC_URL environment variable diff --git a/packages/common/src/client/sync/stream/AbstractRemote.ts b/packages/common/src/client/sync/stream/AbstractRemote.ts index 73cd0a281..05724425c 100644 --- a/packages/common/src/client/sync/stream/AbstractRemote.ts +++ b/packages/common/src/client/sync/stream/AbstractRemote.ts @@ -14,6 +14,7 @@ import { version as POWERSYNC_JS_VERSION } from '../../../../package.json'; export type BSONImplementation = typeof BSON; +const POWERSYNC_TRAILING_SLASH_MATCH = /\/+$/; export type RemoteConnector = { fetchCredentials: () => Promise; }; @@ -108,6 +109,11 @@ export abstract class AbstractRemote { return this.credentials!; } this.credentials = await this.connector.fetchCredentials(); + if (this.credentials?.endpoint.match(POWERSYNC_TRAILING_SLASH_MATCH)) { + throw new Error( + 'A trailing forward slash "/" was entered after the POWERSYNC_URL environment variable. Remove the trailing "/" from the variable to fix this error.' + ); + } return this.credentials; } From da7bfc18e72c1f9e8f124e07eb4296b0224beb1f Mon Sep 17 00:00:00 2001 From: Hein Date: Wed, 23 Oct 2024 12:42:10 +0200 Subject: [PATCH 2/2] Add fetchCredentials response to error --- packages/common/src/client/sync/stream/AbstractRemote.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/client/sync/stream/AbstractRemote.ts b/packages/common/src/client/sync/stream/AbstractRemote.ts index 05724425c..abfba091e 100644 --- a/packages/common/src/client/sync/stream/AbstractRemote.ts +++ b/packages/common/src/client/sync/stream/AbstractRemote.ts @@ -111,7 +111,7 @@ export abstract class AbstractRemote { this.credentials = await this.connector.fetchCredentials(); if (this.credentials?.endpoint.match(POWERSYNC_TRAILING_SLASH_MATCH)) { throw new Error( - 'A trailing forward slash "/" was entered after the POWERSYNC_URL environment variable. Remove the trailing "/" from the variable to fix this error.' + `A trailing forward slash "/" was found in the fetchCredentials endpoint: "${this.credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.` ); } return this.credentials;