on master help sign in
Tenth-pass audit: AddContact clears stale error on retry
660cb44Lancelot
core/src/app.rs+24
@@ -881,6 +881,8 @@ impl App for Skrepka {
881 }
881 }
882 }
882 }
883 Event::AddContact { input, nickname } => {
883 Event::AddContact { input, nickname } => {
884+ // Clear a stale error from a previous failed add.
885+ model.error = None;
884 // A nickname is stored in the contacts kv blob, which is
886 // A nickname is stored in the contacts kv blob, which is
885 // rewritten in full on every change. An unbounded nickname
887 // rewritten in full on every change. An unbounded nickname
886 // bloats the blob and every subsequent write.
888 // bloats the blob and every subsequent write.
@@ -3354,6 +3356,28 @@ mod tests {
3354 assert!(m.error.is_some());
3356 assert!(m.error.is_some());
3355 }
3357 }
3356
3358
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+
3357 #[test]
3381 #[test]
3358 fn send_text_enqueues_message_profile_and_outbox() {
3382 fn send_text_enqueues_message_profile_and_outbox() {
3359 let app = Skrepka;
3383 let app = Skrepka;