dns-orchestrator-provider 0.1.2

DNS provider abstraction library for multiple cloud platforms (Cloudflare, Aliyun, DNSPod, Huaweicloud)
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
//! Huawei cloud error mapping
//!
//! Reference: <https://support.huaweicloud.com/api-dns/ErrorCode.html>
//!
//! ## Error code classification (29 core error codes in total)
//!
//! - **Authentication Error (7)**: APIGW.0301, APIGW.0101, APIGW.0303, APIGW.0305, DNS.0005, DNS.0013, DNS.0040
//! - **Permission Denied (4)**: APIGW.0302, APIGW.0306, DNS.0030, DNS.1802
//! - **Quota exceeded (8)**: DNS.0403, DNS.0404, DNS.0405, DNS.0408, DNS.0409, APIGW.0308, DNS.0021, DNS.2002
//! - **Record Operations (4)**: DNS.0312, DNS.0335, DNS.0016 (`RecordExists`), DNS.0313, DNS.0004 (`RecordNotFound`)
//! - **Domain Name Operation (6)**: DNS.0302, DNS.0301, DNS.1206 (`DomainNotFound`), DNS.0213, DNS.0214, DNS.0209 (`DomainLocked`)
//! - **Parameter errors (various)**: DNS.0303(ttl), DNS.0307(type), DNS.0308(value), DNS.0304(name), etc.
//! - **Network Error (5)**: APIGW.0201, DNS.0012, DNS.0015, DNS.0022, DNS.0036
//!
//! ## Unmapped special functions (fallback to Unknown)
//!
//! - Health Check (DNS.11xx): Project not in use
//! - VPC association (DNS.07xx): Project uses Public Zone
//! - PTR record (DNS.05xx): reverse resolution, not used by the project
//! - DNSSEC (DNS.23xx): advanced features
//! - Enterprise Project (DNS.19xx): Enterprise Features

use crate::error::ProviderError;
use crate::traits::{ErrorContext, ProviderErrorMapper, RawApiError};

use super::HuaweicloudProvider;

/// Huawei Cloud error code mapping implementation
impl ProviderErrorMapper for HuaweicloudProvider {
    fn provider_name(&self) -> &'static str {
        "huaweicloud"
    }

    fn map_error(&self, raw: RawApiError, context: ErrorContext) -> ProviderError {
        match raw.code.as_deref() {
            // ============ Authentication error ============
            Some(
                "APIGW.0301" // IAM authentication information error
                | "APIGW.0101" // API does not exist/is not published (wrong authentication path)
                | "APIGW.0303" // APP authentication information error
                | "APIGW.0305" // Generic authentication error
                | "DNS.0005"   // Permission authentication failed
                | "DNS.0013"   // No permission to operate API
                | "DNS.0040",  // The account has not been authenticated by real name
            ) => ProviderError::InvalidCredentials {
                provider: self.provider_name().to_string(),
                raw_message: Some(raw.message),
            },

            // ============ Permission/Operation Denied ============
            Some(
                "APIGW.0302" // IAM users are not allowed access (black/white list restrictions)
                | "APIGW.0306" // API access denied
                | "DNS.0030"   // Operation of this resource is not allowed
                | "DNS.1802",  // Policy does not allow operation
            ) => ProviderError::PermissionDenied {
                provider: self.provider_name().to_string(),
                raw_message: Some(raw.message),
            },

            // ============ Quota limit (resources run out, no retry) ============
            Some(
                "DNS.0403"     // Insufficient Record Set quota
                | "DNS.0404"   // Insufficient Zone quota
                | "DNS.0405"   // Insufficient PTR quota
                | "DNS.0408"   // Insufficient custom line quota
                | "DNS.0409"   // Insufficient line grouping quota
                | "DNS.0021"   // Unable to acquire lock (concurrency violation)
                | "DNS.2002",  // Insufficient tenant quota
            ) => ProviderError::QuotaExceeded {
                provider: self.provider_name().to_string(),
                raw_message: Some(raw.message),
            },

            // ============ Frequency limiting (can be retried) ============
            Some("APIGW.0308") => ProviderError::RateLimited { // Flow control threshold reached (429)
                provider: self.provider_name().to_string(),
                retry_after: None,
                raw_message: Some(raw.message),
            },

            // ============ Record already exists ============
            Some(
                "DNS.0312"     // Recordset name already exists
                | "DNS.0335"   // Duplicate recordset exists
                | "DNS.0016",  // The record already exists or conflicts
            ) => ProviderError::RecordExists {
                provider: self.provider_name().to_string(),
                record_name: context.record_name.unwrap_or_else(|| "<unknown>".to_string()),
                raw_message: Some(raw.message),
            },

            // ============ Record does not exist ============
            Some("DNS.0313" | "DNS.0004") => ProviderError::RecordNotFound {
                provider: self.provider_name().to_string(),
                record_id: context.record_id.unwrap_or_else(|| "<unknown>".to_string()),
                raw_message: Some(raw.message),
            },

            // ============ The domain name does not exist ============
            Some(
                "DNS.0302"     // Zone does not exist
                | "DNS.0101"   // Zone does not exist (old error codes remain for compatibility)
                | "DNS.1206",  // Invalid domain name
            ) => ProviderError::DomainNotFound {
                provider: self.provider_name().to_string(),
                domain: context.domain.unwrap_or_else(|| "<unknown>".to_string()),
                raw_message: Some(raw.message),
            },

            // ============ Domain name is locked/disabled ============
            Some(
                "DNS.0213"     // Domain name has been suspended
                | "DNS.0214"   // The domain name is in an abnormal state
                | "DNS.0209"   // The domain name is not in normal status
                | "DNS.2003"   // Police freeze
                | "DNS.2005"   // Police freeze
                | "DNS.2006",  // Domain name freezing
            ) => ProviderError::DomainLocked {
                provider: self.provider_name().to_string(),
                domain: context.domain.unwrap_or_else(|| "<unknown>".to_string()),
                raw_message: Some(raw.message),
            },

            // ============ Invalid parameter - TTL ============
            Some("DNS.0303" | "DNS.0319") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "ttl".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - record type ============
            Some("DNS.0307") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "type".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - record value ============
            Some("DNS.0308") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "value".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - record name ============
            Some("DNS.0304" | "DNS.0202") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "name".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - subdomain level ============
            Some("DNS.0321") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "subdomain".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - weight ============
            Some("DNS.0323") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "weight".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - line ============
            Some(
                "DNS.0806"     // Line not supported
                | "DNS.1601"   // Invalid line ID
                | "DNS.1602"   // Invalid line name
                | "DNS.1604",  // Line does not exist
            ) => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "line".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - line grouping ============
            Some(
                "DNS.1702"     // Line group contains invalid lines
                | "DNS.1704"   // Line group name already exists
                | "DNS.1706"   // Line group contains duplicate lines
                | "DNS.1707",  // Line grouping does not exist
            ) => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "line_group".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - Record ID ============
            Some("DNS.0309") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "record_id".to_string(),
                detail: raw.message,
            },

            // ============ Invalid parameter - description ============
            Some("DNS.0206" | "DNS.0305") => ProviderError::InvalidParameter {
                provider: self.provider_name().to_string(),
                param: "description".to_string(),
                detail: raw.message,
            },

            // ============ Network/Backend Service Error ============
            Some(
                "APIGW.0201"   // Request malformed/backend unavailable/timed out
                | "DNS.0012"   // VPC service exception
                | "DNS.0015"   // IAM service exception
                | "DNS.0022"   // Cloud Eye service abnormality
                | "DNS.0036",  // Neutron service exception
            ) => ProviderError::NetworkError {
                provider: self.provider_name().to_string(),
                detail: raw.message,
            },

            // ============ Other errors fallback ============
            _ => self.unknown_error(raw),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::traits::{ErrorContext, ProviderErrorMapper, RawApiError};

    fn provider() -> HuaweicloudProvider {
        HuaweicloudProvider::new(String::new(), String::new())
    }

    fn default_ctx() -> ErrorContext {
        ErrorContext::default()
    }

    fn ctx_with_record(name: &str, id: &str) -> ErrorContext {
        ErrorContext {
            record_name: Some(name.to_string()),
            record_id: Some(id.to_string()),
            domain: None,
        }
    }

    fn ctx_with_domain(domain: &str) -> ErrorContext {
        ErrorContext {
            record_name: None,
            record_id: None,
            domain: Some(domain.to_string()),
        }
    }

    // ============ 1. Authentication error ============

    #[test]
    fn auth_apigw_0301() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("APIGW.0301", "iam auth failed"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::InvalidCredentials { .. }));
    }

    #[test]
    fn auth_apigw_0101() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("APIGW.0101", "api not found"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::InvalidCredentials { .. }));
    }

    #[test]
    fn auth_dns_0005() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0005", "auth failed"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::InvalidCredentials { .. }));
    }

    #[test]
    fn auth_dns_0040() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0040", "not verified"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::InvalidCredentials { .. }));
    }

    // ============ 2. Permission Denied ============

    #[test]
    fn permission_apigw_0302() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("APIGW.0302", "access denied"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::PermissionDenied { .. }));
    }

    #[test]
    fn permission_dns_0030() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0030", "resource forbidden"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::PermissionDenied { .. }));
    }

    #[test]
    fn permission_dns_1802() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.1802", "policy denied"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::PermissionDenied { .. }));
    }

    // ============ 3. Quota exceeded ============

    #[test]
    fn quota_dns_0403() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0403", "recordset quota"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::QuotaExceeded { .. }));
    }

    #[test]
    fn quota_dns_0404() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0404", "zone quota"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::QuotaExceeded { .. }));
    }

    #[test]
    fn quota_dns_2002() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.2002", "tenant quota"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::QuotaExceeded { .. }));
    }

    // ============ 4. Frequency limiting ============

    #[test]
    fn rate_limited_apigw_0308() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("APIGW.0308", "throttled"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::RateLimited {
                retry_after: None,
                ..
            }
        ));
    }

    // ============ 5. The record already exists ============

    #[test]
    fn record_exists_dns_0312() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0312", "name exists"),
            ctx_with_record("www", ""),
        );
        assert!(matches!(err, ProviderError::RecordExists { .. }));
    }

    #[test]
    fn record_exists_dns_0335() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0335", "duplicate"),
            ctx_with_record("mx", ""),
        );
        assert!(matches!(err, ProviderError::RecordExists { .. }));
    }

    #[test]
    fn record_exists_dns_0016() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0016", "conflict"),
            ctx_with_record("txt", ""),
        );
        assert!(matches!(err, ProviderError::RecordExists { .. }));
    }

    // ============ 6. The record does not exist ============

    #[test]
    fn record_not_found_dns_0313() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0313", "not found"),
            ctx_with_record("", "rec-123"),
        );
        assert!(matches!(err, ProviderError::RecordNotFound { .. }));
    }

    #[test]
    fn record_not_found_dns_0004() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0004", "not found"),
            ctx_with_record("", "rec-456"),
        );
        assert!(matches!(err, ProviderError::RecordNotFound { .. }));
    }

    // ============ 7. The domain name does not exist ============

    #[test]
    fn domain_not_found_dns_0302() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0302", "zone not found"),
            ctx_with_domain("example.com"),
        );
        assert!(matches!(err, ProviderError::DomainNotFound { .. }));
    }

    #[test]
    fn domain_not_found_dns_0101() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0101", "zone not found"),
            ctx_with_domain("example.com"),
        );
        assert!(matches!(err, ProviderError::DomainNotFound { .. }));
    }

    #[test]
    fn domain_not_found_dns_1206() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.1206", "invalid domain"),
            ctx_with_domain("bad.example"),
        );
        assert!(matches!(err, ProviderError::DomainNotFound { .. }));
    }

    // ============ 8. Domain name is locked ============

    #[test]
    fn domain_locked_dns_0213() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0213", "suspended"),
            ctx_with_domain("locked.com"),
        );
        assert!(matches!(err, ProviderError::DomainLocked { .. }));
    }

    #[test]
    fn domain_locked_dns_0214() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0214", "abnormal"),
            ctx_with_domain("locked.com"),
        );
        assert!(matches!(err, ProviderError::DomainLocked { .. }));
    }

    #[test]
    fn domain_locked_dns_0209() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0209", "not normal"),
            ctx_with_domain("locked.com"),
        );
        assert!(matches!(err, ProviderError::DomainLocked { .. }));
    }

    #[test]
    fn domain_locked_dns_2003() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.2003", "frozen"),
            ctx_with_domain("locked.com"),
        );
        assert!(matches!(err, ProviderError::DomainLocked { .. }));
    }

    // ============ 9. Invalid parameter - TTL ============

    #[test]
    fn invalid_param_ttl_dns_0303() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0303", "ttl invalid"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "ttl"
        ));
    }

    #[test]
    fn invalid_param_ttl_dns_0319() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0319", "ttl out of range"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "ttl"
        ));
    }

    // ============ 10. Invalid parameter - type ============

    #[test]
    fn invalid_param_type_dns_0307() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0307", "bad type"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "type"
        ));
    }

    // ============ 11. Invalid parameter - value ============

    #[test]
    fn invalid_param_value_dns_0308() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0308", "bad value"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "value"
        ));
    }

    // ============ 12. Invalid parameter - name ============

    #[test]
    fn invalid_param_name_dns_0304() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0304", "bad name"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "name"
        ));
    }

    // ============ 13. Invalid parameter - subdomain ============

    #[test]
    fn invalid_param_subdomain_dns_0321() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0321", "too deep"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "subdomain"
        ));
    }

    // ============ 14. Invalid parameter - weight ============

    #[test]
    fn invalid_param_weight_dns_0323() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0323", "bad weight"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "weight"
        ));
    }

    // ============ 15. Invalid parameter - line ============

    #[test]
    fn invalid_param_line_dns_0806() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0806", "unsupported line"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "line"
        ));
    }

    // ============ 16. Invalid parameter - line_group ============

    #[test]
    fn invalid_param_line_group_dns_1702() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.1702", "invalid line in group"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "line_group"
        ));
    }

    // ============ 17. Invalid parameter - record_id ============

    #[test]
    fn invalid_param_record_id_dns_0309() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0309", "bad record id"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "record_id"
        ));
    }

    // ============ 18. Invalid parameter - description ============

    #[test]
    fn invalid_param_description_dns_0206() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0206", "description too long"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::InvalidParameter { ref param, .. } if param == "description"
        ));
    }

    // ============ 19. Network error ============

    #[test]
    fn network_error_apigw_0201() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("APIGW.0201", "backend unavailable"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::NetworkError { .. }));
    }

    #[test]
    fn network_error_dns_0012() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0012", "vpc error"),
            default_ctx(),
        );
        assert!(matches!(err, ProviderError::NetworkError { .. }));
    }

    // ============ 20. Fallback - unknown code ============

    #[test]
    fn fallback_unknown_code() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("TOTALLY.UNKNOWN", "mystery error"),
            default_ctx(),
        );
        assert!(matches!(
            err,
            ProviderError::Unknown {
                ref raw_code,
                ref raw_message,
                ..
            } if raw_code.as_deref() == Some("TOTALLY.UNKNOWN")
                && raw_message == "mystery error"
        ));
    }

    // ============ 21. Fallback - no code ============

    #[test]
    fn fallback_no_code() {
        let p = provider();
        let err = p.map_error(RawApiError::new("something broke"), default_ctx());
        assert!(matches!(
            err,
            ProviderError::Unknown {
                ref raw_code,
                ref raw_message,
                ..
            } if raw_code.is_none() && raw_message == "something broke"
        ));
    }

    // ============ Verification provider_name ============

    #[test]
    fn provider_name_is_huaweicloud() {
        let p = provider();
        assert_eq!(p.provider_name(), "huaweicloud");
    }

    // ============ Validation context field delivery ============

    #[test]
    fn record_exists_carries_record_name() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0312", "exists"),
            ctx_with_record("www.example.com", ""),
        );
        assert!(matches!(
            err,
            ProviderError::RecordExists { record_name, .. } if record_name == "www.example.com"
        ));
    }

    #[test]
    fn record_not_found_carries_record_id() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0313", "not found"),
            ctx_with_record("", "rec-abc-123"),
        );
        assert!(matches!(
            err,
            ProviderError::RecordNotFound { record_id, .. } if record_id == "rec-abc-123"
        ));
    }

    #[test]
    fn domain_not_found_carries_domain() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0302", "zone gone"),
            ctx_with_domain("example.org"),
        );
        assert!(matches!(
            err,
            ProviderError::DomainNotFound { domain, .. } if domain == "example.org"
        ));
    }

    #[test]
    fn domain_locked_carries_domain() {
        let p = provider();
        let err = p.map_error(
            RawApiError::with_code("DNS.0213", "suspended"),
            ctx_with_domain("frozen.io"),
        );
        assert!(matches!(
            err,
            ProviderError::DomainLocked { domain, .. } if domain == "frozen.io"
        ));
    }

    #[test]
    fn default_context_yields_unknown_placeholder() {
        let p = provider();
        let err = p.map_error(RawApiError::with_code("DNS.0312", "exists"), default_ctx());
        assert!(matches!(
            err,
            ProviderError::RecordExists { record_name, .. } if record_name == "<unknown>"
        ));
    }
}