Repository navigation
Description
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 lintwith a script inscripts/, in the style ofscripts/check-event-names.mjs) that reads the RustCODESconstants of allErrorCodetypes and compares them withKNOWN_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.mdlint description.
Acceptance Criteria
- The check passes on the current tree (after adding any real missing codes to
KNOWN_ERROR_CODESor the allow list with a reason). - A Rust code added to a
CODESlist without a frontend entry failsnpm run lint. - A
KNOWN_ERROR_CODESentry without a Rust code (and not on the allow list) failsnpm 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
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity