this repo has no description

chore: Adding value context to at-uri compose errors

Signed-off-by: Nick Gerakines <12125+ngerakines@users.noreply.github.com>

+107 -26
+107 -26
src/matcher.rs
··· 152 152 .collect::<Vec<String>>(); 153 153 154 154 if string_nodes.iter().any(|value| value == &self.expected) { 155 - let aturi = extract_aturi(self.aturi_path.as_ref(), value) 156 - .ok_or(anyhow!("matcher matched but could not create at-uri"))?; 155 + let aturi = extract_aturi(self.aturi_path.as_ref(), value).ok_or(anyhow!( 156 + "matcher matched but could not create at-uri: {:?}", 157 + value 158 + ))?; 157 159 Ok(MatcherResult { 158 160 matched: true, 159 161 aturi, ··· 207 209 .iter() 208 210 .any(|value| value.starts_with(&self.prefix)); 209 211 if found { 210 - let aturi = extract_aturi(self.aturi_path.as_ref(), value) 211 - .ok_or(anyhow!("matcher matched but could not create at-uri"))?; 212 + let aturi = extract_aturi(self.aturi_path.as_ref(), value).ok_or(anyhow!( 213 + "matcher matched but could not create at-uri: {:?}", 214 + value 215 + ))?; 212 216 Ok(MatcherResult { 213 217 matched: true, 214 218 aturi, ··· 278 282 } 279 283 280 284 if last_found != -1 && found_index == self.expected.len() - 1 { 281 - let aturi = extract_aturi(self.aturi_path.as_ref(), value) 282 - .ok_or(anyhow!("matcher matched but could not create at-uri"))?; 285 + let aturi = extract_aturi(self.aturi_path.as_ref(), value).ok_or(anyhow!( 286 + "matcher matched but could not create at-uri: {:?}", 287 + value 288 + ))?; 283 289 return Ok(MatcherResult { 284 290 matched: true, 285 291 aturi, ··· 325 331 let rkey = commit.get("rkey").and_then(|did| did.as_str())?; 326 332 let uri = format!("at://{}/{}/{}", did, collection, rkey); 327 333 return Some(uri); 334 + } 335 + 336 + if Some("app.bsky.feed.like") == rtype { 337 + return event_value 338 + .get("commit") 339 + .and_then(|value| value.get("record")) 340 + .and_then(|value| value.get("subject")) 341 + .and_then(|value| value.get("uri")) 342 + .and_then(|value| value.as_str()) 343 + .map(|value| value.to_string()); 328 344 } 329 345 330 346 None ··· 390 406 println!("{event:?}"); 391 407 let event = event.as_map_ref().map_err(|err| anyhow!(err))?; 392 408 393 - let commit = event.get("commit").ok_or(anyhow!("no commit on event"))?.as_map_ref().map_err(|err| anyhow!(err))?; 394 - let record = commit.get("record").ok_or(anyhow!("no record on event commit"))?.as_map_ref().map_err(|err| anyhow!(err))?; 409 + let commit = event 410 + .get("commit") 411 + .ok_or(anyhow!("no commit on event"))? 412 + .as_map_ref() 413 + .map_err(|err| anyhow!(err))?; 414 + let record = commit 415 + .get("record") 416 + .ok_or(anyhow!("no record on event commit"))? 417 + .as_map_ref() 418 + .map_err(|err| anyhow!(err))?; 395 419 396 - let rtype = record.get("$type").ok_or(anyhow!("no $type on event commit record"))?.as_immutable_string_ref().map_err(|err| anyhow!(err))?; 420 + let rtype = record 421 + .get("$type") 422 + .ok_or(anyhow!("no $type on event commit record"))? 423 + .as_immutable_string_ref() 424 + .map_err(|err| anyhow!(err))?; 397 425 398 - if rtype.as_str() == "app.bsky.feed.post" { 399 - let did = event.get("did").ok_or(anyhow!("no did on event"))?.as_immutable_string_ref().map_err(|err| anyhow!(err))?; 400 - let collection = commit.get("collection").ok_or(anyhow!("no collection on event"))?.as_immutable_string_ref().map_err(|err| anyhow!(err))?; 401 - let rkey = commit.get("rkey").ok_or(anyhow!("no rkey on event commit"))?.as_immutable_string_ref().map_err(|err| anyhow!(err))?; 426 + match rtype.as_str() { 427 + "app.bsky.feed.post" => { 428 + let did = event 429 + .get("did") 430 + .ok_or(anyhow!("no did on event"))? 431 + .as_immutable_string_ref() 432 + .map_err(|err| anyhow!(err))?; 433 + let collection = commit 434 + .get("collection") 435 + .ok_or(anyhow!("no collection on event"))? 436 + .as_immutable_string_ref() 437 + .map_err(|err| anyhow!(err))?; 438 + let rkey = commit 439 + .get("rkey") 440 + .ok_or(anyhow!("no rkey on event commit"))? 441 + .as_immutable_string_ref() 442 + .map_err(|err| anyhow!(err))?; 402 443 403 - return Ok(format!("at://{}/{}/{}", did.as_str(), collection.as_str(), rkey.as_str())); 444 + Ok(format!( 445 + "at://{}/{}/{}", 446 + did.as_str(), 447 + collection.as_str(), 448 + rkey.as_str() 449 + )) 450 + } 451 + _ => Err(anyhow!("no aturi for event")), 404 452 } 405 - 406 - 407 - Err(anyhow!("no aturi for event")) 408 453 } 409 454 410 455 fn build_aturi(event: Dynamic) -> String { ··· 610 655 ( 611 656 "post1.json", 612 657 [ 613 - ("rhai_match_everything.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadb7behk25"), 614 - ("rhai_match_type.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadb7behk25"), 615 - ("rhai_match_poster.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadb7behk25"), 658 + ( 659 + "rhai_match_everything.rhai", 660 + true, 661 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadb7behk25", 662 + ), 663 + ( 664 + "rhai_match_type.rhai", 665 + true, 666 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadb7behk25", 667 + ), 668 + ( 669 + "rhai_match_poster.rhai", 670 + true, 671 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadb7behk25", 672 + ), 616 673 ("rhai_match_reply_root.rhai", false, ""), 617 674 ], 618 675 ), 619 676 ( 620 677 "post2.json", 621 678 [ 622 - ("rhai_match_everything.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25"), 623 - ("rhai_match_type.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25"), 624 - ("rhai_match_poster.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25"), 625 - ("rhai_match_reply_root.rhai", true, "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25"), 679 + ( 680 + "rhai_match_everything.rhai", 681 + true, 682 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25", 683 + ), 684 + ( 685 + "rhai_match_type.rhai", 686 + true, 687 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25", 688 + ), 689 + ( 690 + "rhai_match_poster.rhai", 691 + true, 692 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25", 693 + ), 694 + ( 695 + "rhai_match_reply_root.rhai", 696 + true, 697 + "at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/3laadftr72k25", 698 + ), 626 699 ], 627 700 ), 628 701 ]; ··· 640 713 let matcher = RhaiMatcher::new(&matcher_path.to_string_lossy()) 641 714 .context("could not construct matcher")?; 642 715 let result = matcher.matches(&value)?; 643 - assert_eq!(result.matched, matched, "matched {}: {}", input_json, matcher_file_name); 644 - assert_eq!(result.aturi, aturi, "aturi {}: {}", input_json, matcher_file_name); 716 + assert_eq!( 717 + result.matched, matched, 718 + "matched {}: {}", 719 + input_json, matcher_file_name 720 + ); 721 + assert_eq!( 722 + result.aturi, aturi, 723 + "aturi {}: {}", 724 + input_json, matcher_file_name 725 + ); 645 726 } 646 727 } 647 728