fix(connections): show why a connection failed, and auto-size the URL field - #132
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_errorclassifies by keyword, so it matched nothing and fell through to a fallback that echoed the plumbing verbatim.db_core::error_chain— walks the fullsource()chain, joined by:, skipping adjacent duplicates since some drivers already embed their source's text. Wired into the Postgres and Mongo connect paths pluspool_err/driver_err.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.connect failed: Error occurred while creating a new object: error connecting to serverCould not connect — check the host, port, and credentials.Connection refused — check the host and port.Host not reachable — check the host name.Authentication failed — check the user and password.URL field (
ConnectionForm.tsx,styles.css) — was fixed at two rows withresize: 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+ ascrollHeightautosize helper), capped bymax-heightso it scrolls past ~6 lines. A layout effect covers switching into URL mode, where the field is filled programmatically andonChangehasn'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 theFailed:prefix, which stuttered in front of the backend's now-complete sentence.Testing
yarn lint— 0 errors (23 pre-existing warnings, unchanged frommain)yarn test:unit— 36 files, 321 tests passyarn tsc -b --noEmit— no errors in the touched files. Note:bindings/commands.ts(399)reports aTAURI_CHANNELconflict, but it's pre-existing onmainand in generated code this PR doesn't touch.rustfmt --checkclean on all four Rust files.targetis 13G), socargo testcan't link. To still verify the logic I extractederror_chain,short_connect_error, andis_driver_noiseverbatim into a single file with their test modules and ranrustc --edition 2021 --test— 9/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
yarn lint, typecheck,yarn test:unit(Rust tests: see caveat above)