Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
648 lines (564 loc) · 22.4 KB
/
Copy patherror.rs
File metadata and controls
648 lines (564 loc) · 22.4 KB
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
use std::{
borrow::Cow,
cell::{BorrowError, BorrowMutError},
error::Error as StdError,
fmt,
};
use magnus::{
Attr, Class, Error as MagnusError, Exception, RModule, RObject, Ruby, TryConvert,
error::ErrorType, exception::ExceptionClass, prelude::*, value::Lazy,
};
use tokio::sync::mpsc::error::SendError;
const ERROR_PREDICATES_IVAR: &str = "wreq_error_predicates";
type ErrorPredicateBits = u64;
macro_rules! define_exception {
($name:ident, $ruby_name:literal, $parent_method:ident) => {
static $name: Lazy<ExceptionClass> = Lazy::new(|ruby| {
ruby.class_object()
.const_get::<_, RModule>(crate::RUBY_MODULE_NAME)
.and_then(|module| module.const_get::<_, ExceptionClass>($ruby_name))
.unwrap_or_else(|_| ruby.$parent_method())
});
};
}
macro_rules! initialize_exception {
($ruby:expr, $module:expr, $name:ident, $ruby_name:literal, $parent:expr) => {{
$module.define_error($ruby_name, $parent)?;
Lazy::force(&$name, $ruby);
}};
}
macro_rules! define_native_error_predicates {
(
$(
$predicate:ident [$role:ident]:
$native_method:ident as $ruby_method:ident
),+ $(,)?
) => {
/// How a native predicate participates in the Ruby error contract.
#[cfg(test)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum ErrorPredicateRole {
NativeKind,
TransportDetail,
Diagnostic,
}
/// Predicates captured from a native `wreq::Error`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
enum ErrorPredicate {
$($predicate),+
}
impl ErrorPredicate {
/// Every predicate retained in Ruby exception metadata.
const ALL: &'static [Self] = &[$(Self::$predicate),+];
/// Return this predicate's position in the compact Ruby metadata.
const fn mask(self) -> ErrorPredicateBits {
1 << (self as u8)
}
/// Return how this native fact participates in the Ruby contract.
#[cfg(test)]
const fn role(self) -> ErrorPredicateRole {
match self {
$(Self::$predicate => ErrorPredicateRole::$role,)+
}
}
/// Evaluate this predicate before the native error is consumed.
fn matches_wreq(self, error: &wreq::Error) -> bool {
match self {
$(Self::$predicate => error.$native_method(),)+
}
}
}
const _: () =
assert!(ErrorPredicate::ALL.len() <= ErrorPredicateBits::BITS as usize);
$(
fn $native_method(rb_self: RObject) -> Result<bool, MagnusError> {
error_has_predicate(rb_self, ErrorPredicate::$predicate)
}
)+
/// Define idiomatic Ruby predicate methods on `Wreq::Error`.
fn include_error_predicates(class: ExceptionClass) -> Result<(), MagnusError> {
$(
class.define_method(
concat!(stringify!($ruby_method), "?"),
magnus::method!($native_method, 0),
)?;
)+
Ok(())
}
};
}
macro_rules! define_ruby_error_categories {
(
$(
$category:ident => $class:ident $(($ruby_name:literal))?
),+ $(,)?
) => {
/// Stable exception categories owned by the Ruby API.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum RubyErrorCategory {
$($category),+
}
impl RubyErrorCategory {
/// Return the Ruby exception class for this stable category.
fn error_class(self) -> &'static Lazy<ExceptionClass> {
match self {
$(Self::$category => &$class,)+
}
}
}
$(
$(define_exception!($class, $ruby_name, exception_runtime_error);)?
)+
/// Define and retain every mapped Ruby exception class.
fn initialize_mapped_errors(
ruby: &Ruby,
gem_module: &RModule,
parent: ExceptionClass,
) -> Result<(), MagnusError> {
$(
$(
initialize_exception!(ruby, gem_module, $class, $ruby_name, parent);
)?
)+
Ok(())
}
};
}
// wreq keeps its error kind private. Keep its mutually exclusive kind predicates
// separate from transport details, which inspect the source chain and may overlap.
// Each entry maps the native method before `as` to the Ruby predicate after it.
// Classification order is declared separately as part of the Ruby contract.
define_native_error_predicates! {
Builder [NativeKind]: is_builder as builder,
Body [NativeKind]: is_body as body,
Tls [NativeKind]: is_tls as tls,
Decode [NativeKind]: is_decode as decoding,
Redirect [NativeKind]: is_redirect as redirect,
Status [NativeKind]: is_status as status,
Upgrade [NativeKind]: is_upgrade as upgrade,
Request [NativeKind]: is_request as request,
ConnectionReset [TransportDetail]:
is_connection_reset as connection_reset,
Timeout [TransportDetail]: is_timeout as timeout,
ProxyConnect [TransportDetail]:
is_proxy_connect as proxy_connect,
Connect [TransportDetail]: is_connect as connect,
}
define_ruby_error_categories! {
Base => WREQ_ERROR,
Builder => BUILDER_ERROR("BuilderError"),
Body => BODY_ERROR("BodyError"),
Tls => TLS_ERROR("TlsError"),
Decoding => DECODING_ERROR("DecodingError"),
Redirect => REDIRECT_ERROR("RedirectError"),
Status => STATUS_ERROR("StatusError"),
Request => REQUEST_ERROR("RequestError"),
ConnectionReset => CONNECTION_RESET_ERROR("ConnectionResetError"),
Timeout => TIMEOUT_ERROR("TimeoutError"),
ProxyConnect => PROXY_CONNECT_ERROR("ProxyConnectError"),
Connect => CONNECT_ERROR("ConnectError"),
}
/// Stable mapping from native facts to Ruby exception categories.
///
/// Non-request kinds keep their existing precedence. Source-chain details are
/// then classified independently of `is_request()`, with the generic request
/// category retained only as a fallback. This order belongs to the Ruby API.
const RUBY_ERROR_CLASSIFICATION: &[(ErrorPredicate, RubyErrorCategory)] = &[
(ErrorPredicate::Builder, RubyErrorCategory::Builder),
(ErrorPredicate::Body, RubyErrorCategory::Body),
(ErrorPredicate::Tls, RubyErrorCategory::Tls),
(ErrorPredicate::Decode, RubyErrorCategory::Decoding),
(ErrorPredicate::Redirect, RubyErrorCategory::Redirect),
(ErrorPredicate::Status, RubyErrorCategory::Status),
(ErrorPredicate::Upgrade, RubyErrorCategory::Base),
(
ErrorPredicate::ConnectionReset,
RubyErrorCategory::ConnectionReset,
),
(ErrorPredicate::Timeout, RubyErrorCategory::Timeout),
(
ErrorPredicate::ProxyConnect,
RubyErrorCategory::ProxyConnect,
),
(ErrorPredicate::Connect, RubyErrorCategory::Connect),
(ErrorPredicate::Request, RubyErrorCategory::Request),
];
/// Native facts exposed to Ruby without changing the exception class.
///
/// Add new overlapping predicates here unless a major release intentionally
/// changes which exception existing rescue clauses receive.
#[cfg(test)]
const RUBY_DIAGNOSTIC_PREDICATES: &[ErrorPredicate] = &[];
/// Native error facts retained after consuming a wreq error.
#[derive(Clone, Copy, Default)]
struct NativeErrorFacts(ErrorPredicateBits);
impl NativeErrorFacts {
/// Restore predicates from compact Ruby metadata.
const fn from_bits(bits: ErrorPredicateBits) -> Self {
Self(bits)
}
/// Return the compact representation stored on the Ruby exception.
const fn bits(self) -> ErrorPredicateBits {
self.0
}
/// Return whether the set contains a native predicate.
const fn contains(self, predicate: ErrorPredicate) -> bool {
self.0 & predicate.mask() != 0
}
/// Include a predicate when its native check succeeds.
#[must_use]
const fn include_if(mut self, predicate: ErrorPredicate, include: bool) -> Self {
if include {
self.0 |= predicate.mask();
}
self
}
/// Classify captured facts using the binding-owned Ruby contract.
fn ruby_category(self) -> RubyErrorCategory {
RUBY_ERROR_CLASSIFICATION
.iter()
.find_map(|&(predicate, category)| self.contains(predicate).then_some(category))
.unwrap_or(RubyErrorCategory::Base)
}
}
impl From<&wreq::Error> for NativeErrorFacts {
/// Snapshot every native predicate before consuming the wreq error.
fn from(error: &wreq::Error) -> Self {
ErrorPredicate::ALL
.iter()
.copied()
.fold(Self::default(), |predicates, predicate| {
predicates.include_if(predicate, predicate.matches_wreq(error))
})
}
}
/// Native error details retained after converting a wreq error to Ruby.
struct ErrorMetadata<'a> {
uri: Option<&'a str>,
status: Option<wreq::StatusCode>,
facts: NativeErrorFacts,
}
/// Format the native error and every cause omitted from its standard message.
///
/// `wreq::Error` already displays its immediate source. Start with that
/// source's cause so the Ruby message reaches the root error without repeating
/// the first native layer.
struct ErrorMessage<'a>(&'a wreq::Error);
impl fmt::Display for ErrorMessage<'_> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self.0, formatter)?;
let mut source = self.0.source().and_then(StdError::source);
while let Some(error) = source {
write!(formatter, ": {error}")?;
source = error.source();
}
Ok(())
}
}
// Stable roots for native errors.
define_exception!(WREQ_ERROR, "Error", exception_runtime_error);
// Keep interruption outside StandardError so a broad transport rescue
// never swallows a Ruby interrupt.
define_exception!(INTERRUPT_ERROR, "InterruptError", exception_interrupt);
// System-level and runtime errors
define_exception!(MEMORY, "MemoryError", exception_runtime_error);
define_exception!(FORK_ERROR, "ForkError", exception_runtime_error);
// Keep these constructors separate even though both currently use MemoryError.
// A future Ruby body API can change either state error without inspecting or
// coupling itself to the native storage mechanism.
/// Build the compatibility error used when a response body operation cannot proceed.
pub fn response_body_unavailable_error(ruby: &Ruby) -> MagnusError {
MagnusError::new(
ruby.get_inner(&MEMORY),
"response body is unavailable for this operation",
)
}
/// Build the compatibility error used when a sender is reused for another request.
pub fn body_sender_reused_error(ruby: &Ruby) -> MagnusError {
MagnusError::new(
ruby.get_inner(&MEMORY),
"body sender has already been used for a request",
)
}
/// Create a `Wreq::InterruptError` when Ruby interrupts a request.
pub fn interrupt_error(ruby: &Ruby) -> MagnusError {
MagnusError::new(ruby.get_inner(&INTERRUPT_ERROR), "request interrupted")
}
/// Build `Wreq::ForkError` without touching inherited native state.
#[cfg(unix)]
pub fn fork_error(ruby: &Ruby, owner_pid: u32, current_pid: u32) -> MagnusError {
MagnusError::new(
ruby.get_inner(&FORK_ERROR),
format!(
"wreq-ruby was loaded in process {owner_pid} and cannot be used after fork in process {current_pid}"
),
)
}
/// Map a failed process-fork handler registration to `Wreq::ForkError`.
#[cfg(unix)]
pub fn fork_handler_error(ruby: &Ruby, err: &std::io::Error) -> MagnusError {
MagnusError::new(
ruby.get_inner(&FORK_ERROR),
format!("failed to initialize process fork tracking: {err}"),
)
}
/// Map a Tokio runtime initialization failure to `Wreq::BuilderError`.
pub fn runtime_initialization_error(ruby: &Ruby, err: &std::io::Error) -> MagnusError {
MagnusError::new(
ruby.get_inner(&BUILDER_ERROR),
format!("failed to initialize Tokio runtime: {err}"),
)
}
/// LocalJumpError for methods that require a Ruby block.
pub fn no_block_given_error(ruby: &Ruby) -> MagnusError {
MagnusError::new(ruby.exception_local_jump_error(), "no block given (yield)")
}
/// Build an `IOError` for writes to a closed request-body sender.
pub fn closed_body_sender_error(ruby: &Ruby) -> MagnusError {
MagnusError::new(ruby.exception_io_error(), "closed body sender")
}
/// Map a failed body-channel send to `IOError`.
pub fn body_sender_send_error<T>(ruby: &Ruby, err: SendError<T>) -> MagnusError {
MagnusError::new(
ruby.exception_io_error(),
format!("closed body sender: {err}"),
)
}
/// Map an immutable sender-state access conflict to `Wreq::BodyError`.
pub fn body_sender_borrow_error(ruby: &Ruby, _err: BorrowError) -> MagnusError {
MagnusError::new(
ruby.get_inner(&BODY_ERROR),
"body sender is currently in use",
)
}
/// Map a mutable sender-state access conflict to `Wreq::BodyError`.
pub fn body_sender_borrow_mut_error(ruby: &Ruby, _err: BorrowMutError) -> MagnusError {
MagnusError::new(
ruby.get_inner(&BODY_ERROR),
"body sender is currently in use",
)
}
/// Map [`wreq::header::InvalidHeaderName`] to corresponding [`magnus::Error`]
pub fn header_name_error(ruby: &Ruby, err: wreq::header::InvalidHeaderName) -> MagnusError {
MagnusError::new(
ruby.get_inner(&BUILDER_ERROR),
format!("invalid header name: {err}"),
)
}
/// Map [`wreq::header::InvalidHeaderValue`] to corresponding [`magnus::Error`]
pub fn header_value_error(ruby: &Ruby, err: wreq::header::InvalidHeaderValue) -> MagnusError {
MagnusError::new(
ruby.get_inner(&BUILDER_ERROR),
format!("invalid header value: {err}"),
)
}
/// Build a `Wreq::BuilderError` for an invalid Ruby header structure.
pub fn header_type_error(ruby: &Ruby, err: &str) -> MagnusError {
MagnusError::new(ruby.get_inner(&BUILDER_ERROR), format!("type error: {err}"))
}
/// Build a `Wreq::BuilderError` for unsupported request JSON values.
pub fn json_serialization_error(ruby: &Ruby, err: MagnusError) -> MagnusError {
MagnusError::new(
ruby.get_inner(&BUILDER_ERROR),
format!("JSON serialization error: {err}"),
)
}
/// Prefix a Magnus error while preserving its Ruby exception class and cause.
pub fn contextualize_magnus_error(err: MagnusError, context: fmt::Arguments<'_>) -> MagnusError {
match err.error_type() {
ErrorType::Error(class, message) => {
MagnusError::new(*class, format!("{context}: {message}"))
}
ErrorType::Exception(exception) => {
let contextualized: Result<Exception, MagnusError> =
exception.funcall("exception", (format!("{context}: {exception}"),));
contextualized.map_or_else(|error| error, MagnusError::from)
}
ErrorType::Jump(_) => err,
}
}
/// Add an option name while preserving the original Ruby exception class.
pub fn option_value_error(option: &str, err: MagnusError) -> MagnusError {
contextualize_magnus_error(err, format_args!("invalid value for :{option}"))
}
/// Build an `ArgumentError` from a validation message.
pub fn argument_error(ruby: &Ruby, message: impl Into<Cow<'static, str>>) -> MagnusError {
MagnusError::new(ruby.exception_arg_error(), message)
}
/// Builds a Ruby `RangeError` from a validation message.
pub fn range_error(ruby: &Ruby, message: impl Into<Cow<'static, str>>) -> MagnusError {
MagnusError::new(ruby.exception_range_error(), message)
}
/// Build a `TypeError` from a conversion message.
pub fn type_error(ruby: &Ruby, message: impl Into<Cow<'static, str>>) -> MagnusError {
MagnusError::new(ruby.exception_type_error(), message)
}
/// Select the Ruby exception class from the binding-owned category.
fn wreq_error_class(ruby: &Ruby, facts: NativeErrorFacts) -> ExceptionClass {
ruby.get_inner(facts.ruby_category().error_class())
}
/// Read one native predicate from a Ruby error, defaulting to false.
fn error_has_predicate(rb_self: RObject, predicate: ErrorPredicate) -> Result<bool, MagnusError> {
rb_self
.ivar_get::<_, Option<ErrorPredicateBits>>(ERROR_PREDICATES_IVAR)
.map(|bits| bits.is_some_and(|bits| NativeErrorFacts::from_bits(bits).contains(predicate)))
}
/// Construct a Ruby exception and attach captured native error metadata.
fn error_with_metadata(
ruby: &Ruby,
class: ExceptionClass,
message: String,
metadata: ErrorMetadata<'_>,
) -> MagnusError {
match class.new_instance((message,)).and_then(|exception| {
let object = RObject::try_convert(exception.as_value())?;
object.ivar_set(ERROR_PREDICATES_IVAR, metadata.facts.bits())?;
if let Some(uri) = metadata.uri {
let uri = ruby.str_new(uri);
uri.freeze();
object.ivar_set("@uri", uri)?;
}
if let Some(status) = metadata.status {
object.ivar_set("@status", status.as_u16())?;
}
Ok(exception)
}) {
Ok(exception) => exception.into(),
Err(error) => error,
}
}
/// Map [`wreq::Error`] to corresponding [`magnus::Error`].
pub fn wreq_error(ruby: &Ruby, err: wreq::Error) -> MagnusError {
let facts = NativeErrorFacts::from(&err);
let class = wreq_error_class(ruby, facts);
let uri = err.uri().map(ToString::to_string);
let status = err.status();
let err = err.without_uri();
let message = ErrorMessage(&err).to_string();
error_with_metadata(
ruby,
class,
message,
ErrorMetadata {
uri: uri.as_deref(),
status,
facts,
},
)
}
/// Define and retain the Ruby exception classes used by the binding.
///
/// # Errors
///
/// Returns the Ruby exception raised while defining an error class.
pub fn include(ruby: &Ruby, gem_module: &RModule) -> Result<(), MagnusError> {
let error_class = gem_module.define_error("Error", ruby.exception_runtime_error())?;
error_class.define_attr("uri", Attr::Read)?;
error_class.define_attr("status", Attr::Read)?;
include_error_predicates(error_class)?;
Lazy::force(&WREQ_ERROR, ruby);
gem_module.define_error("InterruptError", ruby.exception_interrupt())?;
Lazy::force(&INTERRUPT_ERROR, ruby);
initialize_exception!(ruby, gem_module, MEMORY, "MemoryError", error_class);
initialize_exception!(ruby, gem_module, FORK_ERROR, "ForkError", error_class);
initialize_mapped_errors(ruby, gem_module, error_class)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::{
ErrorPredicate, ErrorPredicateRole, NativeErrorFacts, RUBY_DIAGNOSTIC_PREDICATES,
RUBY_ERROR_CLASSIFICATION, RubyErrorCategory,
};
fn facts(entries: &[ErrorPredicate]) -> NativeErrorFacts {
entries
.iter()
.copied()
.fold(NativeErrorFacts::default(), |facts, predicate| {
facts.include_if(predicate, true)
})
}
#[test]
fn error_predicate_bits_are_unique_and_round_trip() {
let facts = ErrorPredicate::ALL.iter().copied().fold(
NativeErrorFacts::default(),
|facts, predicate| {
assert!(!facts.contains(predicate));
facts.include_if(predicate, true)
},
);
assert_eq!(
ErrorPredicate::ALL.len(),
facts.bits().count_ones() as usize
);
let restored = NativeErrorFacts::from_bits(facts.bits());
for &predicate in ErrorPredicate::ALL {
assert!(restored.contains(predicate));
}
}
#[test]
fn ruby_error_contract_covers_every_predicate_once() {
let mut seen = NativeErrorFacts::default();
for &(predicate, _) in RUBY_ERROR_CLASSIFICATION {
assert_ne!(ErrorPredicateRole::Diagnostic, predicate.role());
assert!(
!seen.contains(predicate),
"duplicate predicate: {predicate:?}"
);
seen = seen.include_if(predicate, true);
}
for &predicate in RUBY_DIAGNOSTIC_PREDICATES {
assert_eq!(ErrorPredicateRole::Diagnostic, predicate.role());
assert!(
!seen.contains(predicate),
"duplicate predicate: {predicate:?}"
);
seen = seen.include_if(predicate, true);
}
assert_eq!(ErrorPredicate::ALL.len(), seen.bits().count_ones() as usize);
for &predicate in RUBY_DIAGNOSTIC_PREDICATES {
assert_eq!(RubyErrorCategory::Base, facts(&[predicate]).ruby_category());
}
}
#[test]
fn ruby_error_classification_is_owned_by_the_binding() {
for &(predicate, category) in RUBY_ERROR_CLASSIFICATION {
assert_eq!(category, facts(&[predicate]).ruby_category());
}
assert_eq!(RubyErrorCategory::Base, facts(&[]).ruby_category());
for &(kind, kind_category) in RUBY_ERROR_CLASSIFICATION {
if kind.role() != ErrorPredicateRole::NativeKind || kind == ErrorPredicate::Request {
continue;
}
for &(detail, _) in RUBY_ERROR_CLASSIFICATION {
if detail.role() == ErrorPredicateRole::TransportDetail {
assert_eq!(
kind_category,
facts(&[kind, detail]).ruby_category(),
"native kind {kind:?} must take precedence over {detail:?}"
);
}
}
}
for (index, &(detail, detail_category)) in RUBY_ERROR_CLASSIFICATION.iter().enumerate() {
if detail.role() != ErrorPredicateRole::TransportDetail {
continue;
}
assert_eq!(
detail_category,
facts(&[ErrorPredicate::Request, detail]).ruby_category(),
"transport detail {detail:?} must not depend on the request kind"
);
for &(lower_priority, _) in &RUBY_ERROR_CLASSIFICATION[index + 1..] {
if lower_priority.role() == ErrorPredicateRole::TransportDetail {
assert_eq!(
detail_category,
facts(&[detail, lower_priority]).ruby_category(),
"transport detail {detail:?} must take precedence over {lower_priority:?}"
);
}
}
}
}
}