@@ -318,14 +318,23 @@ impl Emitter {
318318 // Try to send via type-erased trait method
319319 let boxed_value = Box :: new ( value) as Box < dyn Any + Send > ;
320320 sender. try_send_any ( boxed_value) . map_err ( |_returned_value| {
321- // We can't easily distinguish between Full and Closed in the type-erased interface
322- // For now, assume Full (more common case). Capacity is unknown at this level.
323- DbError :: OutboxFull {
324- capacity : 0 , // Unknown at this level
325- #[ cfg( feature = "std" ) ]
326- type_name : core:: any:: type_name :: < T > ( ) . to_string ( ) ,
327- #[ cfg( not( feature = "std" ) ) ]
328- _type_name : ( ) ,
321+ // Check if channel is closed to distinguish error types
322+ if sender. is_closed ( ) {
323+ DbError :: OutboxClosed {
324+ #[ cfg( feature = "std" ) ]
325+ type_name : core:: any:: type_name :: < T > ( ) . to_string ( ) ,
326+ #[ cfg( not( feature = "std" ) ) ]
327+ _type_name : ( ) ,
328+ }
329+ } else {
330+ // Channel is full - now we can report the actual capacity
331+ DbError :: OutboxFull {
332+ capacity : sender. capacity ( ) ,
333+ #[ cfg( feature = "std" ) ]
334+ type_name : core:: any:: type_name :: < T > ( ) . to_string ( ) ,
335+ #[ cfg( not( feature = "std" ) ) ]
336+ _type_name : ( ) ,
337+ }
329338 }
330339 } )
331340 }
@@ -435,6 +444,16 @@ mod tests {
435444 Ok ( ( ) )
436445 }
437446 }
447+
448+ fn capacity ( & self ) -> usize {
449+ // Mock capacity for testing
450+ 100
451+ }
452+
453+ fn is_closed ( & self ) -> bool {
454+ // If should_fail is true, simulate closed channel
455+ self . should_fail
456+ }
438457 }
439458
440459 fn create_test_emitter ( ) -> Emitter {
@@ -548,13 +567,48 @@ mod tests {
548567
549568 match result {
550569 Err ( crate :: DbError :: OutboxFull { capacity, .. } ) => {
551- // Capacity is placeholder (0) at this level
552- assert_eq ! ( capacity, 0 ) ;
570+ // Capacity should now be reported from the mock sender
571+ assert_eq ! ( capacity, 100 ) ;
553572 }
554573 _ => panic ! ( "Expected OutboxFull error" ) ,
555574 }
556575 }
557576
577+ #[ test]
578+ fn test_try_enqueue_channel_closed ( ) {
579+ let emitter = create_test_emitter ( ) ;
580+
581+ // Register a mock sender that simulates closed channel (should_fail=true)
582+ let mock_sender = MockSender :: < TestMessage > :: new ( true , false ) ;
583+ let type_id = TypeId :: of :: < TestMessage > ( ) ;
584+
585+ #[ cfg( feature = "std" ) ]
586+ {
587+ let mut outboxes = emitter. inner . outboxes . lock ( ) . unwrap ( ) ;
588+ outboxes. insert ( type_id, Box :: new ( mock_sender) ) ;
589+ }
590+ #[ cfg( not( feature = "std" ) ) ]
591+ {
592+ let mut outboxes = emitter. inner . outboxes . lock ( ) ;
593+ outboxes. insert ( type_id, Box :: new ( mock_sender) ) ;
594+ }
595+
596+ let msg = TestMessage {
597+ id : 88 ,
598+ content : "closed" ,
599+ } ;
600+
601+ let result = emitter. try_enqueue ( msg) ;
602+ assert ! ( result. is_err( ) ) ;
603+
604+ match result {
605+ Err ( crate :: DbError :: OutboxClosed { .. } ) => {
606+ // Expected - should detect closed channel via is_closed()
607+ }
608+ _ => panic ! ( "Expected OutboxClosed error" ) ,
609+ }
610+ }
611+
558612 // Tests for enqueue method (async)
559613 #[ cfg( feature = "std" ) ]
560614 #[ tokio:: test]
0 commit comments