Skip to content

Check that frontend known error codes match the Rust error codes #1772

Backlog

Description

@smart-ssh-planner

Goal

The frontend's list of known error codes can no longer drift away from the codes the Rust side emits: a code that exists on one side only fails the lint step.

Context

Follow-up of #1680 (PR #1746): during the frontend comment pass it showed that KNOWN_ERROR_CODES in apps/smart-ssh-community/frontend/src/api/errorCodes.ts:60 is maintained by hand next to the generated IPC types (src/generated/ipc.ts). Rust error types implement ErrorCode (crates/core/src/ipc_error.rs:79) and list their codes in a const CODES: &[&str] that a uniqueness test checks. Nothing compares those lists with the frontend set. A new Rust code that is missing in KNOWN_ERROR_CODES shows the untranslated fallback text; a stale frontend entry stays unnoticed. errorCodes.test.ts only checks that each frontend code has DE/EN text.

Requirements

  • Add a check (extend npm run lint with a script in scripts/, in the style of scripts/check-event-names.mjs) that reads the Rust CODES constants of all ErrorCode types and compares them with KNOWN_ERROR_CODES.
  • Codes that are deliberately frontend-only or Rust-only go into an explicit allow list with a reason per entry.
  • The script prints the differing codes and the file to fix.
  • Add the new script to the AGENTS.md lint description.

Acceptance Criteria

  • The check passes on the current tree (after adding any real missing codes to KNOWN_ERROR_CODES or the allow list with a reason).
  • A Rust code added to a CODES list without a frontend entry fails npm run lint.
  • A KNOWN_ERROR_CODES entry without a Rust code (and not on the allow list) fails npm run lint.
  • A stale allow-list entry fails the check.
  • A self-test of the script covers the three failure cases above.
  • Relevant automated tests pass

Technical Notes

Chosen approach: a lint script comparing source text, no codegen. The Rust codes are already collected in the uniqueness test in crates/app-logic/src/error.rs:~300-345 (a hand-written list plus the CODES lists of SshError, AiError, ProfileError, STORE_ERROR_CODES); the check reuses that set (e.g. the test writes it to a file, or the script parses the same sources) so there is one source on the Rust side. Individual CODES constants live in crates/core/src/ipc_error.rs, ssh/error.rs, ssh/auth.rs, profiles/store.rs, ai/error_codes.rs, ai/types.rs, crates/persistence-sqlite/src/error_kind.rs, crates/app-logic/src/error.rs and others; find them with rg "const CODES". Codes created by CommandError::with_code outside an ErrorCode type must be covered too or listed on the allow list. No security-critical module changes behaviour.

Files: scripts/, apps/smart-ssh-community/frontend/package.json, apps/smart-ssh-community/frontend/src/api/errorCodes.ts, AGENTS.md

Spec impact: none

Open questions

  • Generate the code list from Rust (ts-rs export, like ipc.ts) instead of a lint check? Recommendation: no for now; the lint check is smaller and the hand-kept set also holds codes with extra frontend handling. A generated list can replace it later.

Related Work

Activity

  1. added
    tests
    frontend
    follow-up
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upfrontendtests

    Type

    Fields

    Priority

    P3 - Low

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions