mecha10-core 0.8.0

Mecha10 core runtime and foundational types
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
//! Unit tests for Error module
//!
//! Tests comprehensive error handling including:
//! - Error variant creation for all types
//! - Error message formatting and display
//! - Suggestion text generation
//! - Error helper methods (connection_failed, config_validation, etc.)
//! - Error conversion traits (From implementations)
//! - Error context and metadata
//! - Debug formatting
//!
//! These tests do NOT require external dependencies (Redis, etc.)
//! Run with: cargo test --package mecha10-core --test error_unit_tests

use mecha10_core::error::{Mecha10Error, Result};
use std::path::PathBuf;

#[test]
fn test_node_init_error() {
    let err = Mecha10Error::NodeInit("Failed to allocate resources".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Node initialization failed"));
    assert!(msg.contains("Failed to allocate resources"));
}

#[test]
fn test_node_failed_error() {
    let err = Mecha10Error::NodeFailed {
        node_name: "camera_node".to_string(),
        message: "Camera disconnected".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Node 'camera_node' failed"));
    assert!(msg.contains("Camera disconnected"));
}

#[test]
fn test_node_not_found_error() {
    let err = Mecha10Error::NodeNotFound("missing_node".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Node 'missing_node' not found"));
}

#[test]
fn test_config_validation_error_display() {
    let err = Mecha10Error::ConfigValidation {
        field: "max_speed".to_string(),
        message: "Value out of range".to_string(),
        expected: "0.0..=10.0".to_string(),
        got: "15.0".to_string(),
        suggestion: "Set max_speed between 0.0 and 10.0".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Configuration error in field 'max_speed'"));
    assert!(msg.contains("Value out of range"));
    assert!(msg.contains("Expected: 0.0..=10.0"));
    assert!(msg.contains("Got: 15.0"));
    assert!(msg.contains("Suggestion: Set max_speed between 0.0 and 10.0"));
}

#[test]
fn test_config_validation_helper() {
    let err = Mecha10Error::config_validation(
        "max_speed",
        "Value out of range",
        "0.0..=10.0",
        "15.0",
        "Set max_speed between 0.0 and 10.0",
    );

    let msg = err.to_string();
    assert!(msg.contains("max_speed"));
    assert!(msg.contains("Expected: 0.0..=10.0"));
    assert!(msg.contains("Got: 15.0"));
    assert!(msg.contains("Suggestion:"));
}

#[test]
fn test_config_not_found_error() {
    let err = Mecha10Error::ConfigNotFound {
        path: PathBuf::from("/etc/mecha10/config.yaml"),
        env_var: "MECHA10_CONFIG".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Configuration file not found"));
    assert!(msg.contains("/etc/mecha10/config.yaml"));
    assert!(msg.contains("MECHA10_CONFIG"));
    assert!(msg.contains("Suggestion:"));
}

#[test]
fn test_config_not_found_helper() {
    let err = Mecha10Error::config_not_found("/config/app.yaml", "APP_CONFIG");
    let msg = err.to_string();

    assert!(msg.contains("/config/app.yaml"));
    assert!(msg.contains("APP_CONFIG"));
}

#[test]
fn test_config_invalid_error() {
    let err = Mecha10Error::ConfigInvalid(
        "Missing required field 'name'".to_string(),
        "https://schema.mecha.industries/v1".to_string(),
    );
    let msg = err.to_string();

    assert!(msg.contains("Invalid configuration format"));
    assert!(msg.contains("Missing required field 'name'"));
    assert!(msg.contains("Suggestion: Validate against schema at https://schema.mecha.industries/v1"));
}

#[test]
fn test_configuration_error() {
    let err = Mecha10Error::Configuration("Invalid settings".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Configuration error: Invalid settings"));
}

#[test]
fn test_configuration_helper() {
    let err = Mecha10Error::configuration("Missing required parameter");
    let msg = err.to_string();

    assert!(msg.contains("Missing required parameter"));
}

#[test]
fn test_messaging_error_display() {
    let err = Mecha10Error::MessagingError {
        message: "Failed to connect to broker".to_string(),
        suggestion: "Check Redis is running".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Failed to connect to broker"));
    assert!(msg.contains("Suggestion: Check Redis is running"));
}

#[test]
fn test_messaging_error_helper() {
    let err = Mecha10Error::messaging_error("Connection timeout", "Verify network connectivity");
    let msg = err.to_string();

    assert!(msg.contains("Connection timeout"));
    assert!(msg.contains("Verify network connectivity"));
}

#[test]
fn test_messaging_connection_failed_localhost() {
    let err = Mecha10Error::MessagingConnectionFailed {
        url: "localhost:6379".to_string(),
        suggestion: "Start Redis with `redis-server`".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Failed to connect to message broker"));
    assert!(msg.contains("localhost:6379"));
    assert!(msg.contains("Suggestion:"));
}

#[test]
fn test_connection_failed_helper_localhost() {
    let err = Mecha10Error::connection_failed("localhost:6379");
    let msg = err.to_string();

    assert!(msg.contains("localhost:6379"));
    assert!(msg.contains("redis-server"));
    assert!(msg.contains("Suggestion:"));
}

#[test]
fn test_connection_failed_helper_127_0_0_1() {
    let err = Mecha10Error::connection_failed("127.0.0.1:6379");
    let msg = err.to_string();

    assert!(msg.contains("127.0.0.1:6379"));
    assert!(msg.contains("redis-server"));
    assert!(msg.contains("REDIS_URL"));
}

#[test]
fn test_connection_failed_helper_remote() {
    let err = Mecha10Error::connection_failed("redis.example.com:6379");
    let msg = err.to_string();

    assert!(msg.contains("redis.example.com:6379"));
    assert!(msg.contains("Check network connection"));
    assert!(msg.contains("Redis is running"));
}

#[test]
fn test_publish_failed_error() {
    let err = Mecha10Error::PublishFailed {
        topic: "/sensors/camera".to_string(),
        reason: "Connection lost".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Failed to publish message to topic '/sensors/camera'"));
    assert!(msg.contains("Connection lost"));
}

#[test]
fn test_subscribe_failed_error() {
    let err = Mecha10Error::SubscribeFailed {
        topic: "/control/motor".to_string(),
        reason: "Invalid topic format".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Failed to subscribe to topic '/control/motor'"));
    assert!(msg.contains("Invalid topic format"));
}

#[test]
fn test_deserialization_failed_error() {
    let err = Mecha10Error::DeserializationFailed {
        topic: "/sensors/lidar".to_string(),
        expected_type: "LidarScan".to_string(),
        error: "Missing field 'points'".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Message deserialization failed for topic '/sensors/lidar'"));
    assert!(msg.contains("Expected type: LidarScan"));
    assert!(msg.contains("Error: Missing field 'points'"));
}

#[test]
fn test_serialization_failed_error() {
    let err = Mecha10Error::SerializationFailed("Invalid UTF-8 data".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Message serialization failed: Invalid UTF-8 data"));
}

#[test]
fn test_serialization_error_display() {
    let err = Mecha10Error::SerializationError {
        message: "Cannot serialize NaN value".to_string(),
        suggestion: "Use finite numbers only".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Cannot serialize NaN value"));
    assert!(msg.contains("Suggestion: Use finite numbers only"));
}

#[test]
fn test_circuit_breaker_open_error() {
    let err = Mecha10Error::CircuitBreakerOpen {
        service: "camera_service".to_string(),
        message: "Too many failures".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Circuit breaker open for service 'camera_service'"));
    assert!(msg.contains("Too many failures"));
}

#[test]
fn test_model_load_failed_error() {
    let err = Mecha10Error::ModelLoadFailed {
        uri: "mlflow://model/v1".to_string(),
        reason: "Connection refused".to_string(),
        suggestion: "Check MLflow server".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Failed to load model from 'mlflow://model/v1'"));
    assert!(msg.contains("Connection refused"));
    assert!(msg.contains("Suggestion: Check MLflow server"));
}

#[test]
fn test_model_load_failed_helper_mlflow() {
    let err = Mecha10Error::model_load_failed("mlflow://yolov8-nano/production", "Connection refused");
    let msg = err.to_string();

    assert!(msg.contains("mlflow://yolov8-nano/production"));
    assert!(msg.contains("Connection refused"));
    assert!(msg.contains("MLflow"));
    assert!(msg.contains("Suggestion:"));
}

#[test]
fn test_model_load_failed_helper_http() {
    let err = Mecha10Error::model_load_failed("http://example.com/model.onnx", "404 Not Found");
    let msg = err.to_string();

    assert!(msg.contains("http://example.com/model.onnx"));
    assert!(msg.contains("404 Not Found"));
    assert!(msg.contains("Check network connection"));
}

#[test]
fn test_model_load_failed_helper_https() {
    let err = Mecha10Error::model_load_failed("https://example.com/model.onnx", "SSL error");
    let msg = err.to_string();

    assert!(msg.contains("https://example.com/model.onnx"));
    assert!(msg.contains("SSL error"));
    assert!(msg.contains("Check network connection"));
}

#[test]
fn test_model_load_failed_helper_file() {
    let err = Mecha10Error::model_load_failed("/path/to/model.onnx", "File not found");
    let msg = err.to_string();

    assert!(msg.contains("/path/to/model.onnx"));
    assert!(msg.contains("File not found"));
    assert!(msg.contains("Check file exists"));
}

#[test]
fn test_inference_failed_error() {
    let err = Mecha10Error::InferenceFailed("Out of memory".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Model inference failed: Out of memory"));
}

#[test]
fn test_model_not_found_error() {
    let err = Mecha10Error::ModelNotFound {
        model_name: "yolov8-nano".to_string(),
        version: "production".to_string(),
        mlflow_url: "http://localhost:5000".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Model not found in MLflow registry: yolov8-nano/production"));
    assert!(msg.contains("Suggestion: Check MLflow UI at http://localhost:5000"));
}

#[test]
fn test_model_checksum_mismatch_error() {
    let err = Mecha10Error::ModelChecksumMismatch {
        expected: "abc123".to_string(),
        got: "def456".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Model checksum mismatch"));
    assert!(msg.contains("Expected: abc123"));
    assert!(msg.contains("Got: def456"));
    assert!(msg.contains("Suggestion: Re-download the model"));
}

#[test]
fn test_build_failed_error() {
    let err = Mecha10Error::BuildFailed {
        node_name: "vision_node".to_string(),
        stderr: "error: cannot find type `Image` in this scope".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Build failed for node 'vision_node'"));
    assert!(msg.contains("cannot find type `Image`"));
    assert!(msg.contains("Suggestion: Check the error messages above"));
}

#[test]
fn test_hot_reload_failed_error() {
    let err = Mecha10Error::HotReloadFailed("Compilation error".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Hot-reload failed: Compilation error"));
}

#[test]
fn test_runtime_error() {
    let err = Mecha10Error::Runtime("Unexpected state".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Runtime error: Unexpected state"));
}

#[test]
fn test_timeout_error() {
    let err = Mecha10Error::Timeout {
        timeout_ms: 5000,
        operation: "model loading".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Timeout after 5000ms waiting for: model loading"));
}

#[test]
fn test_shutdown_error() {
    let err = Mecha10Error::Shutdown("Failed to stop service".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Shutdown error: Failed to stop service"));
}

#[test]
fn test_file_not_found_error() {
    let err = Mecha10Error::FileNotFound {
        path: PathBuf::from("/data/config.yaml"),
        suggestion: "Create the file or update the path".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("File not found: /data/config.yaml"));
    assert!(msg.contains("Suggestion: Create the file or update the path"));
}

#[test]
fn test_file_not_found_helper() {
    let err = Mecha10Error::file_not_found("/missing/file.txt", "Check the path");
    let msg = err.to_string();

    assert!(msg.contains("/missing/file.txt"));
    assert!(msg.contains("Check the path"));
}

#[test]
fn test_io_error_conversion() {
    let io_err = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Access denied");
    let err: Mecha10Error = io_err.into();
    let msg = err.to_string();

    assert!(msg.contains("IO error"));
    assert!(msg.contains("Access denied"));
}

#[test]
fn test_io_error_display() {
    let err = Mecha10Error::IoError {
        message: "Failed to write to disk".to_string(),
        suggestion: "Check disk space".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Failed to write to disk"));
    assert!(msg.contains("Suggestion: Check disk space"));
}

#[test]
fn test_json_error_conversion() {
    let json_str = "{invalid json}";
    let json_err = serde_json::from_str::<serde_json::Value>(json_str).unwrap_err();
    let err: Mecha10Error = json_err.into();
    let msg = err.to_string();

    assert!(msg.contains("JSON error"));
}

#[test]
fn test_yaml_error() {
    let err = Mecha10Error::Yaml("Invalid YAML syntax at line 5".to_string());
    let msg = err.to_string();

    assert!(msg.contains("YAML error: Invalid YAML syntax at line 5"));
}

#[test]
fn test_redis_error() {
    let err = Mecha10Error::Redis("Connection pool exhausted".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Redis error: Connection pool exhausted"));
}

#[test]
fn test_database_error() {
    let err = Mecha10Error::Database("Constraint violation".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Database error: Constraint violation"));
}

#[test]
fn test_http_error() {
    let err = Mecha10Error::Http("404 Not Found".to_string());
    let msg = err.to_string();

    assert!(msg.contains("HTTP error: 404 Not Found"));
}

#[test]
fn test_other_error() {
    let err = Mecha10Error::Other("Custom error message".to_string());
    let msg = err.to_string();

    assert_eq!(msg, "Custom error message");
}

#[test]
fn test_anyhow_error_conversion() {
    let anyhow_err = anyhow::anyhow!("Something went wrong");
    let err: Mecha10Error = anyhow_err.into();
    let msg = err.to_string();

    assert!(msg.contains("Something went wrong"));
}

#[test]
fn test_result_type_ok() {
    let result: Result<i32> = Ok(42);
    assert!(result.is_ok());
    assert_eq!(result.ok(), Some(42));
}

#[test]
fn test_result_type_err() {
    let result: Result<i32> = Err(Mecha10Error::Runtime("Error".to_string()));
    assert!(result.is_err());
}

#[test]
fn test_debug_formatting() {
    let err = Mecha10Error::NodeInit("Test error".to_string());
    let debug_str = format!("{:?}", err);

    assert!(debug_str.contains("NodeInit"));
    assert!(debug_str.contains("Test error"));
}

#[test]
fn test_debug_formatting_complex() {
    let err = Mecha10Error::ConfigValidation {
        field: "test".to_string(),
        message: "invalid".to_string(),
        expected: "valid".to_string(),
        got: "invalid".to_string(),
        suggestion: "fix it".to_string(),
    };
    let debug_str = format!("{:?}", err);

    assert!(debug_str.contains("ConfigValidation"));
}

#[test]
fn test_error_with_multiple_context_fields() {
    let err = Mecha10Error::DeserializationFailed {
        topic: "/sensors/camera/image".to_string(),
        expected_type: "Image".to_string(),
        error: "Missing field 'width'".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("/sensors/camera/image"));
    assert!(msg.contains("Image"));
    assert!(msg.contains("Missing field 'width'"));
}

#[test]
fn test_pathbuf_in_error() {
    let path = PathBuf::from("/home/user/config.yaml");
    let err = Mecha10Error::ConfigNotFound {
        path: path.clone(),
        env_var: "CONFIG_PATH".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("/home/user/config.yaml"));
}

#[test]
fn test_multiline_error_formatting() {
    let err = Mecha10Error::ConfigValidation {
        field: "timeout".to_string(),
        message: "Invalid value".to_string(),
        expected: "positive number".to_string(),
        got: "-100".to_string(),
        suggestion: "Use a positive timeout value".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("Expected:"));
    assert!(msg.contains("Got:"));
    assert!(msg.contains("Suggestion:"));
}

#[test]
fn test_suggestion_text_in_errors() {
    let errors = vec![
        Mecha10Error::connection_failed("localhost:6379"),
        Mecha10Error::model_load_failed("mlflow://model", "error"),
        Mecha10Error::file_not_found("/file", "create it"),
    ];

    for err in errors {
        let msg = err.to_string();
        assert!(msg.contains("Suggestion:") || msg.contains("→"));
    }
}

#[test]
fn test_error_with_special_characters() {
    let err = Mecha10Error::NodeFailed {
        node_name: "node-with-dashes_and_underscores".to_string(),
        message: "Error with symbols: @#$%^&*()".to_string(),
    };
    let msg = err.to_string();

    assert!(msg.contains("node-with-dashes_and_underscores"));
    assert!(msg.contains("@#$%^&*()"));
}

#[test]
fn test_error_with_empty_strings() {
    let err = Mecha10Error::NodeInit("".to_string());
    let msg = err.to_string();

    assert!(msg.contains("Node initialization failed"));
}

#[test]
fn test_error_with_very_long_message() {
    let long_message = "x".repeat(1000);
    let err = Mecha10Error::Runtime(long_message.clone());
    let msg = err.to_string();

    assert!(msg.contains(&long_message));
}

#[test]
fn test_connection_failed_with_port() {
    let err = Mecha10Error::connection_failed("redis://localhost:6379/0");
    let msg = err.to_string();

    assert!(msg.contains("localhost"));
}

#[test]
fn test_config_validation_with_unicode() {
    let err = Mecha10Error::config_validation("名前", "無効な値", "文字列", "123", "文字列を入力してください");
    let msg = err.to_string();

    assert!(msg.contains("名前"));
    assert!(msg.contains("無効な値"));
}

#[test]
fn test_result_type_inference() {
    fn returns_result() -> Result<String> {
        Ok("success".to_string())
    }

    let result = returns_result();
    assert!(result.is_ok());
}

#[test]
fn test_error_is_send_and_sync() {
    fn assert_send_sync<T: Send + Sync>() {}
    assert_send_sync::<Mecha10Error>();
}

#[test]
fn test_error_is_static() {
    fn assert_static<T: 'static>() {}
    assert_static::<Mecha10Error>();
}

#[test]
fn test_io_to_mecha10_conversion() {
    let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
    let mecha10_err: Mecha10Error = io_err.into();

    match mecha10_err {
        Mecha10Error::Io(_) => {}
        _ => panic!("Expected Io variant"),
    }
}

#[test]
fn test_json_to_mecha10_conversion() {
    let json_err = serde_json::from_str::<serde_json::Value>("invalid").unwrap_err();
    let mecha10_err: Mecha10Error = json_err.into();

    match mecha10_err {
        Mecha10Error::Json(_) => {}
        _ => panic!("Expected Json variant"),
    }
}

#[test]
fn test_anyhow_to_mecha10_conversion() {
    let anyhow_err = anyhow::anyhow!("test error");
    let mecha10_err: Mecha10Error = anyhow_err.into();

    match mecha10_err {
        Mecha10Error::Other(_) => {}
        _ => panic!("Expected Other variant"),
    }
}

#[test]
fn test_pattern_matching_on_errors() {
    let err = Mecha10Error::NodeInit("test".to_string());

    match err {
        Mecha10Error::NodeInit(msg) => assert_eq!(msg, "test"),
        _ => panic!("Expected NodeInit variant"),
    }
}

#[test]
fn test_pattern_matching_on_complex_errors() {
    let err = Mecha10Error::ConfigValidation {
        field: "test".to_string(),
        message: "msg".to_string(),
        expected: "exp".to_string(),
        got: "got".to_string(),
        suggestion: "sug".to_string(),
    };

    match err {
        Mecha10Error::ConfigValidation { field, .. } => {
            assert_eq!(field, "test");
        }
        _ => panic!("Expected ConfigValidation variant"),
    }
}

#[test]
fn test_error_propagation() {
    fn inner_fn() -> Result<()> {
        Err(Mecha10Error::Runtime("inner error".to_string()))
    }

    fn outer_fn() -> Result<()> {
        inner_fn()?;
        Ok(())
    }

    let result = outer_fn();
    assert!(result.is_err());
}

#[test]
fn test_error_with_question_mark_operator() {
    fn read_config() -> Result<String> {
        let _io_result = std::fs::read_to_string("/nonexistent")?;
        Ok("success".to_string())
    }

    let result = read_config();
    assert!(result.is_err());
}