(key: &str, short: &str, schema: &Value, value: &Value)
| 328 | } |
| 329 | |
| 330 | fn check_array_elements(key: &str, short: &str, schema: &Value, value: &Value) -> Result<()> { |
| 331 | if schema.get("type").and_then(Value::as_str) != Some("array") { |
| 332 | return Ok(()); |
| 333 | } |
| 334 | let Some(items_type) = schema |
| 335 | .get("items") |
| 336 | .and_then(|items| items.get("type")) |
| 337 | .and_then(Value::as_str) |
| 338 | else { |
| 339 | return Ok(()); |
| 340 | }; |
| 341 | if !matches!(items_type, "array" | "object") { |
| 342 | return Ok(()); |
| 343 | } |
| 344 | let Some(elements) = value.as_array() else { |
| 345 | return Ok(()); |
| 346 | }; |
| 347 | if let Some(bad) = elements |
| 348 | .iter() |
| 349 | .find(|element| !value_matches_type(element, items_type)) |
| 350 | { |
| 351 | let flag = key.replace('_', "-"); |
| 352 | return Err(TraceDecayError::Config { |
| 353 | message: format!( |
| 354 | "--{flag} expects a JSON array of {items_type}s, but an \ |
| 355 | element is a {}. Pass JSON: --{flag} '<json>' — {}", |
| 356 | json_type_name(bad), |
| 357 | heredoc_hint(short) |
| 358 | ), |
| 359 | }); |
| 360 | } |
| 361 | Ok(()) |
| 362 | } |
| 363 | |
| 364 | fn unknown_key_error( |
| 365 | key: &str, |
no test coverage detected