Skip to content

fix(connections): show why a connection failed, and auto-size the URL field - #132

Merged
oesukam merged 2 commits into
mainfrom
fix/readable-connect-errors
Aug 22, 2026
Merged

fix(connections): show why a connection failed, and auto-size the URL field#132
oesukam merged 2 commits into
mainfrom
fix/readable-connect-errors

Conversation

@oesukam

@oesukam oesukam commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

The connection Test button reported connect failed: Error occurred while creating a new object: error connecting to server — two driver wrapper layers, neither of which names the actual failure. This surfaces the real cause instead, and cleans up the URL input in the same dialog.

What changed

Why the error was unreadable. Driver errors are onion-shaped, and every call site used e.to_string(), which prints only the outermost layer. deadpool contributes "Error occurred while creating a new object", tokio-postgres contributes "error connecting to server"; the real reason (refused / DNS / auth) sits one or two .source() hops down and was being thrown away. short_connect_error classifies by keyword, so it matched nothing and fell through to a fallback that echoed the plumbing verbatim.

  • Added db_core::error_chain — walks the full source() chain, joined by : , skipping adjacent duplicates since some drivers already embed their source's text. Wired into the Postgres and Mongo connect paths plus pool_err/driver_err.
  • With real causes now reaching it, short_connect_error's existing rules fire again. Broadened it (missing role, SSL required, connection reset, unreachable network) and made the fallback lead with actionable advice rather than driver internals.
Underlying cause Before After
(none exposed) connect failed: Error occurred while creating a new object: error connecting to server Could not connect — check the host, port, and credentials.
Refused same as above Connection refused — check the host and port.
Bad DNS same as above Host not reachable — check the host name.
Bad password same as above Authentication failed — check the user and password.

URL field (ConnectionForm.tsx, styles.css) — was fixed at two rows with resize: vertical, so a long connection string had to be scrolled or dragged open by hand, and the grip could grow it far enough to push the dialog's buttons off-screen. It now sizes to its content (resize: none + a scrollHeight autosize helper), capped by max-height so it scrolls past ~6 lines. A layout effect covers switching into URL mode, where the field is filled programmatically and onChange hasn't run yet. Enter is swallowed and newlines are stripped on paste — a URL is a single value, and a stray newline only breaks the parse. Dropped the Failed: prefix, which stuttered in front of the backend's now-complete sentence.

Testing

  • yarn lint — 0 errors (23 pre-existing warnings, unchanged from main)
  • yarn test:unit — 36 files, 321 tests pass
  • yarn tsc -b --noEmit — no errors in the touched files. Note: bindings/commands.ts(399) reports a TAURI_CHANNEL conflict, but it's pre-existing on main and in generated code this PR doesn't touch.
  • rustfmt --check clean on all four Rust files.
  • Rust tests were not run in-workspace. The dev machine is at 100% disk (~186Mi free, target is 13G), so cargo test can't link. To still verify the logic I extracted error_chain, short_connect_error, and is_driver_noise verbatim into a single file with their test modules and ran rustc --edition 2021 --test9/9 pass, including three new tests covering the exact reported string. CI will be the first real in-workspace compile; worth a look at that job.

Checklist

  • PR title follows Conventional Commits
  • Ran the full gate locally: yarn lint, typecheck, yarn test:unit (Rust tests: see caveat above)
  • Updated docs / screenshots if user-facing behavior changed
  • No unrelated changes bundled in

Driver errors are onion-shaped and every call site used `e.to_string()`,
which prints only the outermost layer. deadpool says "Error occurred while
creating a new object" and tokio-postgres says "error connecting to server"
— neither names the failure. The actual cause (refused / DNS / auth) sits
one or two `source()` hops down and was discarded, so short_connect_error
matched none of its keywords and fell through to echoing driver internals.

Add `db_core::error_chain` to flatten the full source chain, and use it on
the Postgres and Mongo connect paths. With real causes reaching it,
short_connect_error's existing rules fire again; also broaden it (missing
role, SSL required, connection reset, unreachable network) and make the
fallback lead with actionable advice instead of plumbing.
The URL textarea was fixed at two rows with `resize: vertical`, so a long
connection string had to be scrolled or dragged open by hand, and the drag
handle could grow it far enough to push the dialog's buttons off-screen.

Size it to its content instead: `resize: none` plus an autosize helper that
sets height from scrollHeight, capped by max-height so it scrolls past ~6
lines. A layout effect covers switching into URL mode, where the field is
filled programmatically and onChange hasn't run.

Also swallow Enter and strip newlines on paste — a URL is a single value,
and a stray newline only breaks the parse — and stop prefixing connect
failures with "Failed:", which stuttered in front of the backend's own
now-complete sentence.
@oesukam
oesukam merged commit 9d66d00 into main Aug 22, 2026
6 checks passed
@oesukam
oesukam deleted the fix/readable-connect-errors branch August 22, 2026 17:07
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.

1 participant