From 2fc54984e43ff1bda4f1a5b6ffc650abcd26978c Mon Sep 17 00:00:00 2001 From: rissrice2105-agent <289161642+rissrice2105-agent@users.noreply.github.com> Date: Fri, 26 Jun 2026 17:19:02 -0600 Subject: [PATCH] fix: report invalid storage URLs clearly --- packages/storage/src/config.ts | 9 ++++++++- packages/storage/src/index.test.ts | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/storage/src/config.ts b/packages/storage/src/config.ts index 86d6de7..8b8ba25 100644 --- a/packages/storage/src/config.ts +++ b/packages/storage/src/config.ts @@ -85,9 +85,16 @@ export function resolveStorageConfig(env: Record): S if (!authToken) { throw new Error(`Remote DB URL requires ${ENV.authToken}.`); } + let hostname: string; + try { + hostname = new URL(url).hostname; + } catch { + throw new Error(`${ENV.url} must be a valid remote libSQL/Turso URL or a local file path.`); + } + // Managed Turso (*.turso.io) gets the cloud tier (managed backups); any other // remote libSQL the user runs themselves is self-hosted. - const tier: StorageTier = /\.turso\.io$/.test(new URL(url).hostname) ? 'cloud' : 'self-hosted'; + const tier: StorageTier = /\.turso\.io$/.test(hostname) ? 'cloud' : 'self-hosted'; return { driver: 'turso', tier, url, authToken }; } diff --git a/packages/storage/src/index.test.ts b/packages/storage/src/index.test.ts index bca9994..03e501e 100644 --- a/packages/storage/src/index.test.ts +++ b/packages/storage/src/index.test.ts @@ -37,6 +37,15 @@ describe('@tronbrowser/storage config', () => { expect(() => resolveStorageConfig({ [ENV.url]: 'libsql://x.turso.io' })).toThrow(/AUTH_TOKEN/); }); + it('reports invalid remote URLs as storage configuration errors', () => { + expect(() => + resolveStorageConfig({ + [ENV.url]: 'not a valid remote url', + [ENV.authToken]: 'tok', + }), + ).toThrow(/TRONBROWSER_DB_URL must be a valid remote libSQL\/Turso URL/); + }); + it('errors when nothing is configured', () => { expect(() => resolveStorageConfig({})).toThrow(/No storage configured/); });