Skip to content

Picking an engine before typing does not blank the page - #577

Merged
WaylandYang merged 1 commit into
devfrom
fix/issue-573
Sep 9, 2026
Merged

Picking an engine before typing does not blank the page#577
WaylandYang merged 1 commit into
devfrom
fix/issue-573

Conversation

@WaylandYang

Copy link
Copy Markdown
Contributor

Closes #573. Thanks @MatheusCylo — reproduced exactly as reported.

Open Administration → Data sources → Add data source, choose "Connection string"
from the engine list, and the whole page is replaced by "Something went wrong!
Cannot read properties of undefined (reading 'trim')". Nothing has been typed yet;
selecting the option is enough.

Why

The dialog rebuilds the connection string on every render:

const conn = spec.build(values);

values holds only the fields somebody has actually typed into, so right after
switching engines it is {}. The raw engine's builder was
(v) => v.conn.trim(), and v.conn is undefined.

The type signature is what let it through. build was declared
(v: Record<string, string>) => string, and an index signature claims every key
yields a string, never undefined. So v.conn.trim() type-checked. The other five
engines survived only because they interpolate into template strings, where
undefined is quietly stringified into "undefined" — the same hole, just silent.

The fix

Make the type tell the truth: build now takes Partial<Record<string, string>>,
which is what it has always been handed.

Turning that on produced six more errors immediately — auth(v.user, v.password) in
three engines and enc(...) in two. Both helpers already handled absent values
correctly (auth tests truthiness, enc should encode ""); only their signatures
said otherwise. They now say what they do. That is the whole class of bug, not just
the one reported instance.

Test

dsSpecs is exported and dsSpecs.test.ts asserts, for every engine, that
building from an empty form and from a half-filled form does not throw, plus that the
raw engine trims. Written against all engines rather than the one that broke, so a
future engine added with a naive builder lands in the same net.

Confirmed RED before the fix: the empty-form assertion failed on raw.

Checked

  • pnpm test 18 passed; pnpm build clean; style guard 46/46.
  • In the browser, switching through all six engines with an empty form: Postgres,
    MySQL, Trino, Databricks, Snowflake, Connection string — no errors, dialog stays
    open. Before the fix the last one blanked the page.
  • Filling the raw engine still works end to end: Name, Engine and the connection
    string field render, and "Test connection" enables.

Not in this change

noUncheckedIndexedAccess in tsconfig would have caught this at compile time and
would catch the next one. It is worth doing and it is not a two-line change, so it
belongs on its own.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: WaylandYang <wayland0916@gmail.com>
@WaylandYang
WaylandYang merged commit eb27c4a into dev Sep 9, 2026
4 checks passed
@WaylandYang
WaylandYang deleted the fix/issue-573 branch September 9, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trying to add a data source with a "Connection string" engine results in an error

1 participant