@@ -21,10 +21,8 @@ use tokio::sync::{
2121use tokio_util:: sync:: CancellationToken ;
2222use tracing:: { debug, error} ;
2323
24- use credentialsd_common:: {
25- memfd:: write_secret,
26- model:: { BackgroundEvent , Error } ,
27- } ;
24+ use super :: CredentialServiceError ;
25+ use credentialsd_common:: { memfd:: write_secret, model:: BackgroundEvent } ;
2826
2927use crate :: model:: { CredentialRequest , CredentialResponse } ;
3028
@@ -148,13 +146,15 @@ impl HybridHandler for InternalHybridHandler {
148146 }
149147 . map_err ( |err| match err {
150148 WebAuthnError :: Ctap ( CtapError :: PINAuthBlocked ) => {
151- Error :: PinAttemptsExhausted
149+ CredentialServiceError :: PinAttemptsExhausted
150+ }
151+ WebAuthnError :: Ctap ( CtapError :: NoCredentials ) => {
152+ CredentialServiceError :: NoCredentials
152153 }
153- WebAuthnError :: Ctap ( CtapError :: NoCredentials ) => Error :: NoCredentials ,
154154 WebAuthnError :: Ctap ( CtapError :: CredentialExcluded ) => {
155- Error :: CredentialExcluded
155+ CredentialServiceError :: CredentialExcluded
156156 }
157- _ => Error :: AuthenticatorError ,
157+ _ => CredentialServiceError :: AuthenticatorError ,
158158 } )
159159 } ;
160160
@@ -166,15 +166,26 @@ impl HybridHandler for InternalHybridHandler {
166166 Some ( resp) => resp,
167167 None => {
168168 tracing:: debug!( "Hybrid handler cancelled, stopping processing" ) ;
169- Err ( Error :: Internal ( "Request cancelled" . to_string ( ) ) )
169+ Err ( CredentialServiceError :: RequestCancelled )
170170 }
171171 } ;
172172
173173 let terminal_state = match response {
174- Ok ( auth_response) => HybridStateInternal :: Completed ( auth_response) ,
175- Err ( err) => HybridStateInternal :: Failed ( err) ,
174+ Ok ( auth_response) => Some ( HybridStateInternal :: Completed ( auth_response) ) ,
175+ Err ( CredentialServiceError :: RequestCancelled ) => {
176+ // Cancelled by another transport winning or an explicit user cancel.
177+ // Do not emit a Failed state — complete_request was already called
178+ // by the winning path, and emitting Failed here would produce a
179+ // spurious ErrorAuthenticator in the UI and a redundant
180+ // complete_request invocation.
181+ tracing:: debug!( "Hybrid handler cancelled, exiting silently" ) ;
182+ None
183+ }
184+ Err ( err) => Some ( HybridStateInternal :: Failed ( err) ) ,
176185 } ;
177- if let Err ( err) = tx. send ( terminal_state) . await {
186+ if let Some ( state) = terminal_state
187+ && let Err ( err) = tx. send ( state) . await
188+ {
178189 tracing:: error!( "Failed to send caBLE update: {:?}" , err)
179190 }
180191 } ) ;
@@ -203,11 +214,7 @@ pub(super) enum HybridStateInternal {
203214 /// Authenticator data
204215 Completed ( CredentialResponse ) ,
205216
206- Failed ( Error ) ,
207- // TODO(cancellation)
208- // This isn't actually sent from the server.
209- #[ allow( dead_code) ]
210- UserCancelled ,
217+ Failed ( CredentialServiceError ) ,
211218}
212219
213220// this is here to prevent making HybridStateInternal public to the whole crate.
@@ -233,10 +240,7 @@ pub enum HybridState {
233240 Completed ,
234241
235242 /// Hybrid operation failed.
236- Failed ( Error ) ,
237-
238- // This isn't actually sent from the server.
239- UserCancelled ,
243+ Failed ( CredentialServiceError ) ,
240244}
241245
242246impl From < HybridStateInternal > for HybridState {
@@ -246,7 +250,6 @@ impl From<HybridStateInternal> for HybridState {
246250 HybridStateInternal :: Connecting => HybridState :: Connecting ,
247251 HybridStateInternal :: Connected => HybridState :: Connected ,
248252 HybridStateInternal :: Completed ( _) => HybridState :: Completed ,
249- HybridStateInternal :: UserCancelled => HybridState :: UserCancelled ,
250253 HybridStateInternal :: Failed ( err) => HybridState :: Failed ( err) ,
251254 }
252255 }
@@ -269,14 +272,25 @@ impl From<&HybridState> for BackgroundEvent {
269272 HybridState :: Connecting => BackgroundEvent :: HybridConnecting ,
270273 HybridState :: Connected => BackgroundEvent :: HybridConnected ,
271274 HybridState :: Completed => BackgroundEvent :: CeremonyCompleted ,
272- HybridState :: UserCancelled => BackgroundEvent :: ErrorCancelled ,
273- HybridState :: Failed ( Error :: AuthenticatorError ) => BackgroundEvent :: ErrorAuthenticator ,
274- HybridState :: Failed ( Error :: NoCredentials ) => BackgroundEvent :: ErrorNoCredentials ,
275- HybridState :: Failed ( Error :: CredentialExcluded ) => {
275+ HybridState :: Failed ( CredentialServiceError :: AuthenticatorError ) => {
276+ BackgroundEvent :: ErrorAuthenticator
277+ }
278+ HybridState :: Failed ( CredentialServiceError :: NoCredentials ) => {
279+ BackgroundEvent :: ErrorNoCredentials
280+ }
281+ HybridState :: Failed ( CredentialServiceError :: CredentialExcluded ) => {
276282 BackgroundEvent :: ErrorCredentialExcluded
277283 }
278- HybridState :: Failed ( Error :: PinAttemptsExhausted ) => BackgroundEvent :: ErrorAuthenticator ,
279- HybridState :: Failed ( Error :: Internal ( _) ) => BackgroundEvent :: ErrorInternal ,
284+ HybridState :: Failed ( CredentialServiceError :: PinAttemptsExhausted ) => {
285+ BackgroundEvent :: ErrorAuthenticator
286+ }
287+ // This should currently never be reached, but we'll likely use it in future refactoring
288+ HybridState :: Failed ( CredentialServiceError :: RequestCancelled ) => {
289+ BackgroundEvent :: ErrorCancelled
290+ }
291+ HybridState :: Failed ( CredentialServiceError :: Internal ( _) ) => {
292+ BackgroundEvent :: ErrorInternal
293+ }
280294 }
281295 }
282296}
@@ -302,7 +316,9 @@ async fn handle_hybrid_updates(
302316 CableUpdate :: Connected => Some ( HybridStateInternal :: Connected ) ,
303317 CableUpdate :: Error ( transport_error) => {
304318 error ! ( ?transport_error, "Hybrid transport error" ) ;
305- Some ( HybridStateInternal :: Failed ( Error :: AuthenticatorError ) )
319+ Some ( HybridStateInternal :: Failed (
320+ CredentialServiceError :: AuthenticatorError ,
321+ ) )
306322 }
307323 } ,
308324 } ;
0 commit comments