on master help sign in
Tenth-pass audit: AddContact clears stale error on retry

AddContact did not clear model.error at entry. If the user got "invalid public key" or "nickname too long" and then fixed the input, the old error stayed visible in the AddContact form until the success path cleared it. The success path does clear it (line 902), but the clearing at entry is the consistent pattern now applied to send_text (8th pass), SaveProfile (8th pass), and SetBlocked (9th pass). This completes the set: every user-action handler that can fail now clears a stale error before processing. Test: add_contact_clears_a_stale_error_on_success

commit660cb4467f174b2830cc4b2be4a10e94f3360159 authorLancelot <montelot-dev@typeable.io> dateTue 14 Jul 2026, 04:08 (3 months ago) parent492430c
1 file changed+24
core/src/app.rs+24
core/src/app.rs+24
@@ -881,6 +881,8 @@ impl App for Skrepka {
881881 }
882882 }
883883 Event::AddContact { input, nickname } => {
884+ // Clear a stale error from a previous failed add.
885+ model.error = None;
884886 // A nickname is stored in the contacts kv blob, which is
885887 // rewritten in full on every change. An unbounded nickname
886888 // bloats the blob and every subsequent write.
@@ -3354,6 +3356,28 @@ mod tests {
33543356 assert!(m.error.is_some());
33553357 }
33563358
3359+ /// A stale error from a previous failed add is cleared on the next attempt,
3360+ /// so the AddContact form does not show an old error after the user fixes
3361+ /// the input and tries again.
3362+ #[test]
3363+ fn add_contact_clears_a_stale_error_on_success() {
3364+ let app = Skrepka;
3365+ let mut m = with_identity();
3366+ m.error = Some("invalid public key".into());
3367+
3368+ let peer = peer_hex(9);
3369+ let _ = app.update(
3370+ Event::AddContact {
3371+ input: peer.clone(),
3372+ nickname: "Bob".into(),
3373+ },
3374+ &mut m,
3375+ );
3376+
3377+ assert!(m.error.is_none(), "a successful add clears the stale error");
3378+ assert!(m.contacts.contains_key(&peer));
3379+ }
3380+
33573381 #[test]
33583382 fn send_text_enqueues_message_profile_and_outbox() {
33593383 let app = Skrepka;