Skip to main content

memscope_rs/error/
conversions.rs

1//! Error type conversions to MemScopeError
2//!
3//! Provides conversions from various module-specific error types
4//! to the unified MemScopeError type for centralized error handling.
5
6use crate::core::error::{MemScopeError, MemoryOperation, SystemErrorType};
7
8use super::error_manager::IntoMemScopeError;
9
10// Implement IntoMemScopeError for AsyncError
11impl IntoMemScopeError for crate::capture::backends::async_types::AsyncError {
12    fn into_memscope_error(self, module: &str) -> MemScopeError {
13        use crate::capture::backends::async_types::AsyncError;
14
15        match self {
16            AsyncError::Initialization {
17                component,
18                message,
19                recoverable: _,
20            } => MemScopeError::config(component, message.as_ref()),
21            AsyncError::TaskTracking {
22                operation,
23                message,
24                task_id,
25            } => {
26                let context = task_id.map(|id| format!("task_id: {}", id));
27                let operation_str = format!("{:?}", operation);
28                MemScopeError::memory_with_context(
29                    MemoryOperation::Tracking,
30                    message.as_ref(),
31                    format!(
32                        "{}: {} - {:?}",
33                        module,
34                        operation_str,
35                        context.unwrap_or_default()
36                    ),
37                )
38            }
39            AsyncError::AllocationTracking {
40                event_type,
41                message,
42                allocation_size,
43            } => {
44                let context = allocation_size.map(|size| format!("size: {} bytes", size));
45                let event_type_str = format!("{:?}", event_type);
46                MemScopeError::memory_with_context(
47                    MemoryOperation::Allocation,
48                    message.as_ref(),
49                    format!(
50                        "{}: {} - {:?}",
51                        module,
52                        event_type_str,
53                        context.unwrap_or_default()
54                    ),
55                )
56            }
57            AsyncError::System {
58                operation: _,
59                message,
60            } => MemScopeError::system(
61                SystemErrorType::Threading,
62                format!("{}: {}", module, message),
63            ),
64        }
65    }
66}
67
68// Implement IntoMemScopeError for ExportError
69impl IntoMemScopeError for crate::render_engine::export::ExportError {
70    fn into_memscope_error(self, module: &str) -> MemScopeError {
71        use crate::render_engine::export::ExportError;
72
73        match self {
74            ExportError::Io(err) => MemScopeError::system_with_source(
75                SystemErrorType::Io,
76                format!("{}: IO error", module),
77                err,
78            ),
79            ExportError::Json(err) => MemScopeError::system_with_source(
80                SystemErrorType::Serialization,
81                format!("{}: JSON error", module),
82                err,
83            ),
84            ExportError::ExportFailed(msg) => {
85                MemScopeError::export_partial("general", format!("{}: {}", module, msg))
86            }
87        }
88    }
89}
90
91// Implement IntoMemScopeError for TrackingError (capture::types)
92impl IntoMemScopeError for crate::capture::types::TrackingError {
93    fn into_memscope_error(self, module: &str) -> MemScopeError {
94        use crate::capture::types::TrackingError;
95
96        match self {
97            TrackingError::AllocationFailed(msg) => MemScopeError::memory_with_context(
98                MemoryOperation::Allocation,
99                msg.as_str(),
100                module,
101            ),
102            TrackingError::DeallocationFailed(msg) => MemScopeError::memory_with_context(
103                MemoryOperation::Deallocation,
104                msg.as_str(),
105                module,
106            ),
107            TrackingError::TrackingDisabled => {
108                MemScopeError::config(module, "Memory tracking is disabled")
109            }
110            TrackingError::InvalidPointer(msg) => MemScopeError::memory_with_context(
111                MemoryOperation::Validation,
112                msg.as_str(),
113                module,
114            ),
115            TrackingError::SerializationError(msg) => MemScopeError::system(
116                SystemErrorType::Serialization,
117                format!("{}: {}", module, msg),
118            ),
119            TrackingError::VisualizationError(msg) => {
120                MemScopeError::export("visualization", format!("{}: {}", module, msg))
121            }
122            TrackingError::ThreadSafetyError(msg) => {
123                MemScopeError::system(SystemErrorType::Threading, format!("{}: {}", module, msg))
124            }
125            TrackingError::ConfigurationError(msg) => MemScopeError::config(module, msg.as_str()),
126            TrackingError::AnalysisError(msg) => MemScopeError::analysis(module, msg.as_str()),
127            TrackingError::ExportError(msg) => {
128                MemScopeError::export("general", format!("{}: {}", module, msg))
129            }
130            TrackingError::MemoryCorruption(msg) => MemScopeError::memory_with_context(
131                MemoryOperation::Validation,
132                msg.as_str(),
133                module,
134            ),
135            TrackingError::UnsafeOperationDetected(msg) => {
136                MemScopeError::analysis("unsafe", format!("{}: {}", module, msg))
137            }
138            TrackingError::FFIError(msg) => {
139                MemScopeError::analysis("ffi", format!("{}: {}", module, msg))
140            }
141            TrackingError::ScopeError(msg) => {
142                MemScopeError::memory_with_context(MemoryOperation::Tracking, msg.as_str(), module)
143            }
144            TrackingError::BorrowCheckError(msg) => {
145                MemScopeError::analysis("borrow", format!("{}: {}", module, msg))
146            }
147            TrackingError::LifetimeError(msg) => {
148                MemScopeError::analysis("lifetime", format!("{}: {}", module, msg))
149            }
150            TrackingError::TypeInferenceError(msg) => {
151                MemScopeError::analysis("type", format!("{}: {}", module, msg))
152            }
153            TrackingError::PerformanceError(msg) => {
154                MemScopeError::system(SystemErrorType::Io, format!("{}: {}", module, msg))
155            }
156            TrackingError::ResourceExhausted(msg) => {
157                MemScopeError::system(SystemErrorType::Io, format!("{}: {}", module, msg))
158            }
159            TrackingError::InternalError(msg) => {
160                MemScopeError::internal(format!("{}: {}", module, msg))
161            }
162            TrackingError::IoError(msg) => {
163                MemScopeError::system(SystemErrorType::Io, format!("{}: {}", module, msg))
164            }
165            TrackingError::LockError(msg) => {
166                MemScopeError::system(SystemErrorType::Locking, format!("{}: {}", module, msg))
167            }
168            TrackingError::ChannelError(msg) => {
169                MemScopeError::system(SystemErrorType::Channel, format!("{}: {}", module, msg))
170            }
171            TrackingError::ThreadError(msg) => {
172                MemScopeError::system(SystemErrorType::Threading, format!("{}: {}", module, msg))
173            }
174            TrackingError::InitializationError(msg) => MemScopeError::config(module, msg.as_str()),
175            TrackingError::NotImplemented(msg) => {
176                MemScopeError::internal(format!("{}: {}", module, msg))
177            }
178            TrackingError::ValidationError(msg) => MemScopeError::memory_with_context(
179                MemoryOperation::Validation,
180                msg.as_str(),
181                module,
182            ),
183            TrackingError::InvalidOperation(msg) => {
184                MemScopeError::memory_with_context(MemoryOperation::Tracking, msg.as_str(), module)
185            }
186            TrackingError::LockContention(msg) => {
187                MemScopeError::system(SystemErrorType::Locking, format!("{}: {}", module, msg))
188            }
189            TrackingError::DataError(msg) => {
190                MemScopeError::memory_with_context(MemoryOperation::Tracking, msg.as_str(), module)
191            }
192        }
193    }
194}
195
196// Implement IntoMemScopeError for TrackingError (core::types)
197impl IntoMemScopeError for crate::core::types::TrackingError {
198    fn into_memscope_error(self, module: &str) -> MemScopeError {
199        use crate::core::types::TrackingError;
200
201        match self {
202            TrackingError::AllocationFailed(msg) => MemScopeError::memory_with_context(
203                MemoryOperation::Allocation,
204                msg.as_str(),
205                module,
206            ),
207            TrackingError::DeallocationFailed(msg) => MemScopeError::memory_with_context(
208                MemoryOperation::Deallocation,
209                msg.as_str(),
210                module,
211            ),
212            TrackingError::TrackingDisabled => {
213                MemScopeError::config(module, "Memory tracking is disabled")
214            }
215            TrackingError::InvalidPointer(msg) => MemScopeError::memory_with_context(
216                MemoryOperation::Validation,
217                msg.as_str(),
218                module,
219            ),
220            TrackingError::SerializationError(msg) => MemScopeError::system(
221                SystemErrorType::Serialization,
222                format!("{}: {}", module, msg),
223            ),
224            TrackingError::VisualizationError(msg) => {
225                MemScopeError::export("visualization", format!("{}: {}", module, msg))
226            }
227            TrackingError::ThreadSafetyError(msg) => {
228                MemScopeError::system(SystemErrorType::Threading, format!("{}: {}", module, msg))
229            }
230            TrackingError::ConfigurationError(msg) => MemScopeError::config(module, msg.as_str()),
231            TrackingError::AnalysisError(msg) => MemScopeError::analysis(module, msg.as_str()),
232            TrackingError::ExportError(msg) => {
233                MemScopeError::export("general", format!("{}: {}", module, msg))
234            }
235            TrackingError::MemoryCorruption(msg) => MemScopeError::memory_with_context(
236                MemoryOperation::Validation,
237                msg.as_str(),
238                module,
239            ),
240            TrackingError::UnsafeOperationDetected(msg) => {
241                MemScopeError::analysis("unsafe", format!("{}: {}", module, msg))
242            }
243            TrackingError::FFIError(msg) => {
244                MemScopeError::analysis("ffi", format!("{}: {}", module, msg))
245            }
246            TrackingError::ScopeError(msg) => {
247                MemScopeError::memory_with_context(MemoryOperation::Tracking, msg.as_str(), module)
248            }
249            TrackingError::BorrowCheckError(msg) => {
250                MemScopeError::analysis("borrow", format!("{}: {}", module, msg))
251            }
252            TrackingError::LifetimeError(msg) => {
253                MemScopeError::analysis("lifetime", format!("{}: {}", module, msg))
254            }
255            TrackingError::TypeInferenceError(msg) => {
256                MemScopeError::analysis("type", format!("{}: {}", module, msg))
257            }
258            TrackingError::PerformanceError(msg) => {
259                MemScopeError::system(SystemErrorType::Io, format!("{}: {}", module, msg))
260            }
261            TrackingError::ResourceExhausted(msg) => {
262                MemScopeError::system(SystemErrorType::Io, format!("{}: {}", module, msg))
263            }
264            TrackingError::InternalError(msg) => {
265                MemScopeError::internal(format!("{}: {}", module, msg))
266            }
267            TrackingError::IoError(msg) => {
268                MemScopeError::system(SystemErrorType::Io, format!("{}: {}", module, msg))
269            }
270            TrackingError::LockError(msg) => {
271                MemScopeError::system(SystemErrorType::Locking, format!("{}: {}", module, msg))
272            }
273            TrackingError::ChannelError(msg) => {
274                MemScopeError::system(SystemErrorType::Channel, format!("{}: {}", module, msg))
275            }
276            TrackingError::ThreadError(msg) => {
277                MemScopeError::system(SystemErrorType::Threading, format!("{}: {}", module, msg))
278            }
279            TrackingError::InitializationError(msg) => MemScopeError::config(module, msg.as_str()),
280            TrackingError::NotImplemented(msg) => {
281                MemScopeError::internal(format!("{}: {}", module, msg))
282            }
283            TrackingError::ValidationError(msg) => MemScopeError::memory_with_context(
284                MemoryOperation::Validation,
285                msg.as_str(),
286                module,
287            ),
288            TrackingError::InvalidOperation(msg) => {
289                MemScopeError::memory_with_context(MemoryOperation::Tracking, msg.as_str(), module)
290            }
291            TrackingError::LockContention(msg) => {
292                MemScopeError::system(SystemErrorType::Locking, format!("{}: {}", module, msg))
293            }
294            TrackingError::DataError(msg) => {
295                MemScopeError::memory_with_context(MemoryOperation::Tracking, msg.as_str(), module)
296            }
297        }
298    }
299}
300
301#[cfg(test)]
302mod tests {
303    use super::*;
304    use std::sync::Arc;
305
306    #[test]
307    fn test_async_error_conversion() {
308        use crate::capture::backends::async_types::AsyncError;
309
310        let error = AsyncError::Initialization {
311            component: "test".into(),
312            message: "failed".into(),
313            recoverable: false,
314        };
315        let memscope_error = error.into_memscope_error("test_module");
316
317        assert!(matches!(
318            memscope_error,
319            MemScopeError::Configuration { .. }
320        ));
321    }
322
323    #[test]
324    fn test_tracking_error_conversion() {
325        use crate::capture::types::TrackingError;
326
327        let error = TrackingError::AllocationFailed("test failed".to_string());
328        let memscope_error = error.into_memscope_error("test_module");
329
330        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
331    }
332
333    #[test]
334    fn test_async_error_task_tracking_conversion() {
335        use crate::capture::backends::async_types::{AsyncError, TaskOperation};
336
337        let error = AsyncError::TaskTracking {
338            operation: TaskOperation::IdGeneration,
339            message: Arc::from("task error"),
340            task_id: Some(123),
341        };
342        let memscope_error = error.into_memscope_error("test_module");
343
344        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
345    }
346
347    #[test]
348    fn test_async_error_task_tracking_no_id() {
349        use crate::capture::backends::async_types::{AsyncError, TaskOperation};
350
351        let error = AsyncError::TaskTracking {
352            operation: TaskOperation::Registration,
353            message: Arc::from("no task id"),
354            task_id: None,
355        };
356        let memscope_error = error.into_memscope_error("test_module");
357
358        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
359    }
360
361    #[test]
362    fn test_async_error_allocation_tracking_conversion() {
363        use crate::capture::backends::async_types::{AllocationEventType, AsyncError};
364
365        let error = AsyncError::AllocationTracking {
366            event_type: AllocationEventType::Allocation,
367            message: Arc::from("alloc error"),
368            allocation_size: Some(1024),
369        };
370        let memscope_error = error.into_memscope_error("test_module");
371
372        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
373    }
374
375    #[test]
376    fn test_async_error_allocation_tracking_no_size() {
377        use crate::capture::backends::async_types::{AllocationEventType, AsyncError};
378
379        let error = AsyncError::AllocationTracking {
380            event_type: AllocationEventType::Deallocation,
381            message: Arc::from("dealloc error"),
382            allocation_size: None,
383        };
384        let memscope_error = error.into_memscope_error("test_module");
385
386        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
387    }
388
389    #[test]
390    fn test_async_error_system_conversion() {
391        use crate::capture::backends::async_types::AsyncError;
392
393        let error = AsyncError::System {
394            operation: Arc::from("test_op"),
395            message: Arc::from("system error"),
396        };
397        let memscope_error = error.into_memscope_error("test_module");
398
399        assert!(matches!(memscope_error, MemScopeError::System { .. }));
400    }
401
402    #[test]
403    fn test_export_error_io_conversion() {
404        use crate::render_engine::export::ExportError;
405        use std::io;
406
407        let error = ExportError::Io(io::Error::new(io::ErrorKind::NotFound, "file not found"));
408        let memscope_error = error.into_memscope_error("export_module");
409
410        assert!(matches!(memscope_error, MemScopeError::System { .. }));
411    }
412
413    #[test]
414    fn test_export_error_json_conversion() {
415        use crate::render_engine::export::ExportError;
416
417        let error = ExportError::Json(serde_json::from_str::<i32>("invalid json").unwrap_err());
418        let memscope_error = error.into_memscope_error("export_module");
419
420        assert!(matches!(memscope_error, MemScopeError::System { .. }));
421    }
422
423    #[test]
424    fn test_export_error_export_failed_conversion() {
425        use crate::render_engine::export::ExportError;
426
427        let error = ExportError::ExportFailed("export failed".to_string());
428        let memscope_error = error.into_memscope_error("export_module");
429
430        assert!(matches!(memscope_error, MemScopeError::Export { .. }));
431    }
432
433    #[test]
434    fn test_tracking_error_deallocation_failed() {
435        use crate::capture::types::TrackingError;
436
437        let error = TrackingError::DeallocationFailed("dealloc failed".to_string());
438        let memscope_error = error.into_memscope_error("test_module");
439
440        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
441    }
442
443    #[test]
444    fn test_tracking_error_tracking_disabled() {
445        use crate::capture::types::TrackingError;
446
447        let error = TrackingError::TrackingDisabled;
448        let memscope_error = error.into_memscope_error("test_module");
449
450        assert!(matches!(
451            memscope_error,
452            MemScopeError::Configuration { .. }
453        ));
454    }
455
456    #[test]
457    fn test_tracking_error_invalid_pointer() {
458        use crate::capture::types::TrackingError;
459
460        let error = TrackingError::InvalidPointer("bad pointer".to_string());
461        let memscope_error = error.into_memscope_error("test_module");
462
463        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
464    }
465
466    #[test]
467    fn test_tracking_error_serialization_error() {
468        use crate::capture::types::TrackingError;
469
470        let error = TrackingError::SerializationError("serde error".to_string());
471        let memscope_error = error.into_memscope_error("test_module");
472
473        assert!(matches!(memscope_error, MemScopeError::System { .. }));
474    }
475
476    #[test]
477    fn test_tracking_error_visualization_error() {
478        use crate::capture::types::TrackingError;
479
480        let error = TrackingError::VisualizationError("viz error".to_string());
481        let memscope_error = error.into_memscope_error("test_module");
482
483        assert!(matches!(memscope_error, MemScopeError::Export { .. }));
484    }
485
486    #[test]
487    fn test_tracking_error_thread_safety_error() {
488        use crate::capture::types::TrackingError;
489
490        let error = TrackingError::ThreadSafetyError("thread error".to_string());
491        let memscope_error = error.into_memscope_error("test_module");
492
493        assert!(matches!(memscope_error, MemScopeError::System { .. }));
494    }
495
496    #[test]
497    fn test_tracking_error_configuration_error() {
498        use crate::capture::types::TrackingError;
499
500        let error = TrackingError::ConfigurationError("config error".to_string());
501        let memscope_error = error.into_memscope_error("test_module");
502
503        assert!(matches!(
504            memscope_error,
505            MemScopeError::Configuration { .. }
506        ));
507    }
508
509    #[test]
510    fn test_tracking_error_analysis_error() {
511        use crate::capture::types::TrackingError;
512
513        let error = TrackingError::AnalysisError("analysis error".to_string());
514        let memscope_error = error.into_memscope_error("test_module");
515
516        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
517    }
518
519    #[test]
520    fn test_tracking_error_export_error() {
521        use crate::capture::types::TrackingError;
522
523        let error = TrackingError::ExportError("export error".to_string());
524        let memscope_error = error.into_memscope_error("test_module");
525
526        assert!(matches!(memscope_error, MemScopeError::Export { .. }));
527    }
528
529    #[test]
530    fn test_tracking_error_memory_corruption() {
531        use crate::capture::types::TrackingError;
532
533        let error = TrackingError::MemoryCorruption("corruption detected".to_string());
534        let memscope_error = error.into_memscope_error("test_module");
535
536        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
537    }
538
539    #[test]
540    fn test_tracking_error_unsafe_operation() {
541        use crate::capture::types::TrackingError;
542
543        let error = TrackingError::UnsafeOperationDetected("unsafe code".to_string());
544        let memscope_error = error.into_memscope_error("test_module");
545
546        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
547    }
548
549    #[test]
550    fn test_tracking_error_ffi_error() {
551        use crate::capture::types::TrackingError;
552
553        let error = TrackingError::FFIError("ffi boundary error".to_string());
554        let memscope_error = error.into_memscope_error("test_module");
555
556        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
557    }
558
559    #[test]
560    fn test_tracking_error_scope_error() {
561        use crate::capture::types::TrackingError;
562
563        let error = TrackingError::ScopeError("scope error".to_string());
564        let memscope_error = error.into_memscope_error("test_module");
565
566        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
567    }
568
569    #[test]
570    fn test_tracking_error_borrow_check_error() {
571        use crate::capture::types::TrackingError;
572
573        let error = TrackingError::BorrowCheckError("borrow error".to_string());
574        let memscope_error = error.into_memscope_error("test_module");
575
576        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
577    }
578
579    #[test]
580    fn test_tracking_error_lifetime_error() {
581        use crate::capture::types::TrackingError;
582
583        let error = TrackingError::LifetimeError("lifetime error".to_string());
584        let memscope_error = error.into_memscope_error("test_module");
585
586        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
587    }
588
589    #[test]
590    fn test_tracking_error_type_inference_error() {
591        use crate::capture::types::TrackingError;
592
593        let error = TrackingError::TypeInferenceError("type error".to_string());
594        let memscope_error = error.into_memscope_error("test_module");
595
596        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
597    }
598
599    #[test]
600    fn test_tracking_error_performance_error() {
601        use crate::capture::types::TrackingError;
602
603        let error = TrackingError::PerformanceError("slow".to_string());
604        let memscope_error = error.into_memscope_error("test_module");
605
606        assert!(matches!(memscope_error, MemScopeError::System { .. }));
607    }
608
609    #[test]
610    fn test_tracking_error_resource_exhausted() {
611        use crate::capture::types::TrackingError;
612
613        let error = TrackingError::ResourceExhausted("out of memory".to_string());
614        let memscope_error = error.into_memscope_error("test_module");
615
616        assert!(matches!(memscope_error, MemScopeError::System { .. }));
617    }
618
619    #[test]
620    fn test_tracking_error_internal_error() {
621        use crate::capture::types::TrackingError;
622
623        let error = TrackingError::InternalError("internal bug".to_string());
624        let memscope_error = error.into_memscope_error("test_module");
625
626        assert!(matches!(memscope_error, MemScopeError::Internal { .. }));
627    }
628
629    #[test]
630    fn test_tracking_error_io_error() {
631        use crate::capture::types::TrackingError;
632
633        let error = TrackingError::IoError("io failed".to_string());
634        let memscope_error = error.into_memscope_error("test_module");
635
636        assert!(matches!(memscope_error, MemScopeError::System { .. }));
637    }
638
639    #[test]
640    fn test_tracking_error_lock_error() {
641        use crate::capture::types::TrackingError;
642
643        let error = TrackingError::LockError("lock poisoned".to_string());
644        let memscope_error = error.into_memscope_error("test_module");
645
646        assert!(matches!(memscope_error, MemScopeError::System { .. }));
647    }
648
649    #[test]
650    fn test_tracking_error_channel_error() {
651        use crate::capture::types::TrackingError;
652
653        let error = TrackingError::ChannelError("channel closed".to_string());
654        let memscope_error = error.into_memscope_error("test_module");
655
656        assert!(matches!(memscope_error, MemScopeError::System { .. }));
657    }
658
659    #[test]
660    fn test_tracking_error_thread_error() {
661        use crate::capture::types::TrackingError;
662
663        let error = TrackingError::ThreadError("thread panic".to_string());
664        let memscope_error = error.into_memscope_error("test_module");
665
666        assert!(matches!(memscope_error, MemScopeError::System { .. }));
667    }
668
669    #[test]
670    fn test_tracking_error_initialization_error() {
671        use crate::capture::types::TrackingError;
672
673        let error = TrackingError::InitializationError("init failed".to_string());
674        let memscope_error = error.into_memscope_error("test_module");
675
676        assert!(matches!(
677            memscope_error,
678            MemScopeError::Configuration { .. }
679        ));
680    }
681
682    #[test]
683    fn test_tracking_error_not_implemented() {
684        use crate::capture::types::TrackingError;
685
686        let error = TrackingError::NotImplemented("todo".to_string());
687        let memscope_error = error.into_memscope_error("test_module");
688
689        assert!(matches!(memscope_error, MemScopeError::Internal { .. }));
690    }
691
692    #[test]
693    fn test_tracking_error_validation_error() {
694        use crate::capture::types::TrackingError;
695
696        let error = TrackingError::ValidationError("invalid data".to_string());
697        let memscope_error = error.into_memscope_error("test_module");
698
699        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
700    }
701
702    #[test]
703    fn test_tracking_error_invalid_operation() {
704        use crate::capture::types::TrackingError;
705
706        let error = TrackingError::InvalidOperation("bad op".to_string());
707        let memscope_error = error.into_memscope_error("test_module");
708
709        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
710    }
711
712    #[test]
713    fn test_tracking_error_lock_contention() {
714        use crate::capture::types::TrackingError;
715
716        let error = TrackingError::LockContention("high contention".to_string());
717        let memscope_error = error.into_memscope_error("test_module");
718
719        assert!(matches!(memscope_error, MemScopeError::System { .. }));
720    }
721
722    #[test]
723    fn test_tracking_error_data_error() {
724        use crate::capture::types::TrackingError;
725
726        let error = TrackingError::DataError("corrupt data".to_string());
727        let memscope_error = error.into_memscope_error("test_module");
728
729        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
730    }
731
732    #[test]
733    fn test_core_tracking_error_allocation_failed() {
734        use crate::core::types::TrackingError;
735
736        let error = TrackingError::AllocationFailed("core alloc failed".to_string());
737        let memscope_error = error.into_memscope_error("core_module");
738
739        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
740    }
741
742    #[test]
743    fn test_core_tracking_error_deallocation_failed() {
744        use crate::core::types::TrackingError;
745
746        let error = TrackingError::DeallocationFailed("core dealloc failed".to_string());
747        let memscope_error = error.into_memscope_error("core_module");
748
749        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
750    }
751
752    #[test]
753    fn test_core_tracking_error_tracking_disabled() {
754        use crate::core::types::TrackingError;
755
756        let error = TrackingError::TrackingDisabled;
757        let memscope_error = error.into_memscope_error("core_module");
758
759        assert!(matches!(
760            memscope_error,
761            MemScopeError::Configuration { .. }
762        ));
763    }
764
765    #[test]
766    fn test_core_tracking_error_invalid_pointer() {
767        use crate::core::types::TrackingError;
768
769        let error = TrackingError::InvalidPointer("core bad pointer".to_string());
770        let memscope_error = error.into_memscope_error("core_module");
771
772        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
773    }
774
775    #[test]
776    fn test_core_tracking_error_serialization_error() {
777        use crate::core::types::TrackingError;
778
779        let error = TrackingError::SerializationError("core serde error".to_string());
780        let memscope_error = error.into_memscope_error("core_module");
781
782        assert!(matches!(memscope_error, MemScopeError::System { .. }));
783    }
784
785    #[test]
786    fn test_core_tracking_error_visualization_error() {
787        use crate::core::types::TrackingError;
788
789        let error = TrackingError::VisualizationError("core viz error".to_string());
790        let memscope_error = error.into_memscope_error("core_module");
791
792        assert!(matches!(memscope_error, MemScopeError::Export { .. }));
793    }
794
795    #[test]
796    fn test_core_tracking_error_thread_safety_error() {
797        use crate::core::types::TrackingError;
798
799        let error = TrackingError::ThreadSafetyError("core thread error".to_string());
800        let memscope_error = error.into_memscope_error("core_module");
801
802        assert!(matches!(memscope_error, MemScopeError::System { .. }));
803    }
804
805    #[test]
806    fn test_core_tracking_error_configuration_error() {
807        use crate::core::types::TrackingError;
808
809        let error = TrackingError::ConfigurationError("core config error".to_string());
810        let memscope_error = error.into_memscope_error("core_module");
811
812        assert!(matches!(
813            memscope_error,
814            MemScopeError::Configuration { .. }
815        ));
816    }
817
818    #[test]
819    fn test_core_tracking_error_analysis_error() {
820        use crate::core::types::TrackingError;
821
822        let error = TrackingError::AnalysisError("core analysis error".to_string());
823        let memscope_error = error.into_memscope_error("core_module");
824
825        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
826    }
827
828    #[test]
829    fn test_core_tracking_error_export_error() {
830        use crate::core::types::TrackingError;
831
832        let error = TrackingError::ExportError("core export error".to_string());
833        let memscope_error = error.into_memscope_error("core_module");
834
835        assert!(matches!(memscope_error, MemScopeError::Export { .. }));
836    }
837
838    #[test]
839    fn test_core_tracking_error_memory_corruption() {
840        use crate::core::types::TrackingError;
841
842        let error = TrackingError::MemoryCorruption("core corruption".to_string());
843        let memscope_error = error.into_memscope_error("core_module");
844
845        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
846    }
847
848    #[test]
849    fn test_core_tracking_error_unsafe_operation() {
850        use crate::core::types::TrackingError;
851
852        let error = TrackingError::UnsafeOperationDetected("core unsafe".to_string());
853        let memscope_error = error.into_memscope_error("core_module");
854
855        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
856    }
857
858    #[test]
859    fn test_core_tracking_error_ffi_error() {
860        use crate::core::types::TrackingError;
861
862        let error = TrackingError::FFIError("core ffi error".to_string());
863        let memscope_error = error.into_memscope_error("core_module");
864
865        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
866    }
867
868    #[test]
869    fn test_core_tracking_error_scope_error() {
870        use crate::core::types::TrackingError;
871
872        let error = TrackingError::ScopeError("core scope error".to_string());
873        let memscope_error = error.into_memscope_error("core_module");
874
875        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
876    }
877
878    #[test]
879    fn test_core_tracking_error_borrow_check_error() {
880        use crate::core::types::TrackingError;
881
882        let error = TrackingError::BorrowCheckError("core borrow error".to_string());
883        let memscope_error = error.into_memscope_error("core_module");
884
885        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
886    }
887
888    #[test]
889    fn test_core_tracking_error_lifetime_error() {
890        use crate::core::types::TrackingError;
891
892        let error = TrackingError::LifetimeError("core lifetime error".to_string());
893        let memscope_error = error.into_memscope_error("core_module");
894
895        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
896    }
897
898    #[test]
899    fn test_core_tracking_error_type_inference_error() {
900        use crate::core::types::TrackingError;
901
902        let error = TrackingError::TypeInferenceError("core type error".to_string());
903        let memscope_error = error.into_memscope_error("core_module");
904
905        assert!(matches!(memscope_error, MemScopeError::Analysis { .. }));
906    }
907
908    #[test]
909    fn test_core_tracking_error_performance_error() {
910        use crate::core::types::TrackingError;
911
912        let error = TrackingError::PerformanceError("core slow".to_string());
913        let memscope_error = error.into_memscope_error("core_module");
914
915        assert!(matches!(memscope_error, MemScopeError::System { .. }));
916    }
917
918    #[test]
919    fn test_core_tracking_error_resource_exhausted() {
920        use crate::core::types::TrackingError;
921
922        let error = TrackingError::ResourceExhausted("core oom".to_string());
923        let memscope_error = error.into_memscope_error("core_module");
924
925        assert!(matches!(memscope_error, MemScopeError::System { .. }));
926    }
927
928    #[test]
929    fn test_core_tracking_error_internal_error() {
930        use crate::core::types::TrackingError;
931
932        let error = TrackingError::InternalError("core internal".to_string());
933        let memscope_error = error.into_memscope_error("core_module");
934
935        assert!(matches!(memscope_error, MemScopeError::Internal { .. }));
936    }
937
938    #[test]
939    fn test_core_tracking_error_io_error() {
940        use crate::core::types::TrackingError;
941
942        let error = TrackingError::IoError("core io failed".to_string());
943        let memscope_error = error.into_memscope_error("core_module");
944
945        assert!(matches!(memscope_error, MemScopeError::System { .. }));
946    }
947
948    #[test]
949    fn test_core_tracking_error_lock_error() {
950        use crate::core::types::TrackingError;
951
952        let error = TrackingError::LockError("core lock poisoned".to_string());
953        let memscope_error = error.into_memscope_error("core_module");
954
955        assert!(matches!(memscope_error, MemScopeError::System { .. }));
956    }
957
958    #[test]
959    fn test_core_tracking_error_channel_error() {
960        use crate::core::types::TrackingError;
961
962        let error = TrackingError::ChannelError("core channel closed".to_string());
963        let memscope_error = error.into_memscope_error("core_module");
964
965        assert!(matches!(memscope_error, MemScopeError::System { .. }));
966    }
967
968    #[test]
969    fn test_core_tracking_error_thread_error() {
970        use crate::core::types::TrackingError;
971
972        let error = TrackingError::ThreadError("core thread panic".to_string());
973        let memscope_error = error.into_memscope_error("core_module");
974
975        assert!(matches!(memscope_error, MemScopeError::System { .. }));
976    }
977
978    #[test]
979    fn test_core_tracking_error_initialization_error() {
980        use crate::core::types::TrackingError;
981
982        let error = TrackingError::InitializationError("core init failed".to_string());
983        let memscope_error = error.into_memscope_error("core_module");
984
985        assert!(matches!(
986            memscope_error,
987            MemScopeError::Configuration { .. }
988        ));
989    }
990
991    #[test]
992    fn test_core_tracking_error_not_implemented() {
993        use crate::core::types::TrackingError;
994
995        let error = TrackingError::NotImplemented("core todo".to_string());
996        let memscope_error = error.into_memscope_error("core_module");
997
998        assert!(matches!(memscope_error, MemScopeError::Internal { .. }));
999    }
1000
1001    #[test]
1002    fn test_core_tracking_error_validation_error() {
1003        use crate::core::types::TrackingError;
1004
1005        let error = TrackingError::ValidationError("core invalid".to_string());
1006        let memscope_error = error.into_memscope_error("core_module");
1007
1008        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
1009    }
1010
1011    #[test]
1012    fn test_core_tracking_error_invalid_operation() {
1013        use crate::core::types::TrackingError;
1014
1015        let error = TrackingError::InvalidOperation("core bad op".to_string());
1016        let memscope_error = error.into_memscope_error("core_module");
1017
1018        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
1019    }
1020
1021    #[test]
1022    fn test_core_tracking_error_lock_contention() {
1023        use crate::core::types::TrackingError;
1024
1025        let error = TrackingError::LockContention("core contention".to_string());
1026        let memscope_error = error.into_memscope_error("core_module");
1027
1028        assert!(matches!(memscope_error, MemScopeError::System { .. }));
1029    }
1030
1031    #[test]
1032    fn test_core_tracking_error_data_error() {
1033        use crate::core::types::TrackingError;
1034
1035        let error = TrackingError::DataError("core corrupt".to_string());
1036        let memscope_error = error.into_memscope_error("core_module");
1037
1038        assert!(matches!(memscope_error, MemScopeError::Memory { .. }));
1039    }
1040}