Skip to content

fix(ssh): clarify duplicate connection errors#2741

Open
janburzinski wants to merge 3 commits into
mainfrom
emdash/ssh-conn-error-clearer-38js7
Open

fix(ssh): clarify duplicate connection errors#2741
janburzinski wants to merge 3 commits into
mainfrom
emdash/ssh-conn-error-clearer-38js7

Conversation

@janburzinski

Copy link
Copy Markdown
Collaborator

Description

  • clarifies duplicate ssh connection errors
  • blocks saving duplicate connection names

Screenshot/Recording (if applicable)

https://cap.link/b1xa9ta279attrr

Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks or explained why not
  • I updated docs when behavior or setup changed
  • I added or updated tests when behavior changed, or explained why not
  • I only added comments where the logic is not obvious
  • I used Conventional Commits for commit
    messages and, when possible, the PR title

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves the duplicate SSH connection name experience by adding both a server-side guard in saveConnection and a real-time client-side check in the modal. IPC error messages are now stripped of the Electron prefix and, when applicable, translated from raw SQLite constraint text to a human-readable message.

  • controller.ts: A DB query is executed before every save; it uses ne(id, connectionId) in the edit path so renaming a connection to its own current name is still allowed.
  • add-ssh-conn-modal.tsx: The Save button is disabled live via form.Subscribe + findDuplicateConnection, an inline field error is shown for duplicates, and the catch path for both save and test now calls formatSshConnectionError which strips the Error invoking remote method 'ssh.*': IPC prefix before display.
  • controller.db.test.ts: Two new integration tests cover the rejection of a new connection whose name already exists and the acceptance of an edit that keeps the existing name.

Confidence Score: 5/5

Safe to merge — the change adds a purely additive guard with no impact on the existing happy path.

The server-side duplicate check is correctly scoped (edit vs. create branching), the renderer-side check provides immediate feedback without being the sole line of defence, IPC error formatting is handled defensively, and two new integration tests cover the key cases. No existing behaviour is altered.

No files require special attention.

Important Files Changed

Filename Overview
apps/emdash-desktop/src/main/core/ssh/controller.ts Adds a pre-save duplicate-name query with correct edit-vs-create branching (ne excludes the current row on edits); logic is sound and matches the new tests.
apps/emdash-desktop/src/renderer/lib/components/add-ssh-conn-modal.tsx Adds findDuplicateConnection for live button-disable and field error, and formatSshConnectionError to strip Electron IPC prefixes and map raw UNIQUE constraint errors to friendly text; changes are well-scoped.
apps/emdash-desktop/src/main/core/ssh/controller.db.test.ts Renames describe block to cover the controller broadly and adds two focused integration tests for duplicate rejection and edit-without-rename acceptance.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([User clicks Save]) --> B{Button disabled?\nfindDuplicateConnection\nin renderer store}
    B -- Yes / duplicate --> C[Button disabled — field error shown]
    B -- No --> D[onSubmit fires]
    D --> E{findDuplicateConnection\ncalled again in handler}
    E -- Duplicate found\n(e.g. Enter key bypass) --> F[setTestState idle\nsetTestResult null\nreturn early]
    F --> G[finally: setIsSubmitting false]
    E -- No duplicate --> H[IPC → saveConnection on main]
    H --> I{DB query:\nname exists &&\nid ≠ current?}
    I -- Yes --> J[throw user-friendly Error]
    J --> K[IPC error bubbles to renderer]
    K --> L[formatSshConnectionError:\nstrip IPC prefix\ncheck UNIQUE constraint text]
    L --> M[setTestResult error message]
    I -- No --> N[Insert / upsert connection]
    N --> O[onSuccess callback]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A([User clicks Save]) --> B{Button disabled?\nfindDuplicateConnection\nin renderer store}
    B -- Yes / duplicate --> C[Button disabled — field error shown]
    B -- No --> D[onSubmit fires]
    D --> E{findDuplicateConnection\ncalled again in handler}
    E -- Duplicate found\n(e.g. Enter key bypass) --> F[setTestState idle\nsetTestResult null\nreturn early]
    F --> G[finally: setIsSubmitting false]
    E -- No duplicate --> H[IPC → saveConnection on main]
    H --> I{DB query:\nname exists &&\nid ≠ current?}
    I -- Yes --> J[throw user-friendly Error]
    J --> K[IPC error bubbles to renderer]
    K --> L[formatSshConnectionError:\nstrip IPC prefix\ncheck UNIQUE constraint text]
    L --> M[setTestResult error message]
    I -- No --> N[Insert / upsert connection]
    N --> O[onSuccess callback]
Loading

Reviews (1): Last reviewed commit: "refactor(ssh): reuse duplicate connectio..." | Re-trigger Greptile

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