MCPcopy Create free account
hub / github.com/hashintel/hash / try_collect_multiple_errors

Function try_collect_multiple_errors

libs/error-stack/src/ext/iter.rs:220–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218
219 #[test]
220 fn try_collect_multiple_errors() {
221 let iter = (0..5).map(|i| {
222 if i % 2 == 0 {
223 Ok(i)
224 } else {
225 Err(Report::new(CustomError(i)))
226 }
227 });
228
229 let result: Result<Vec<_>, Report<[CustomError]>> = iter.try_collect_reports();
230 let report = result.expect_err("should have failed");
231
232 let contexts: BTreeSet<_> = report.current_contexts().collect();
233 assert_eq!(contexts.len(), 2);
234 assert!(contexts.contains(&CustomError(1)));
235 assert!(contexts.contains(&CustomError(3)));
236 }
237
238 #[test]
239 fn try_collect_multiple_errors_bounded() {

Callers

nothing calls this directly

Calls 7

OkInterface · 0.85
ErrInterface · 0.85
collectMethod · 0.80
current_contextsMethod · 0.80
CustomErrorClass · 0.70
mapMethod · 0.45
try_collect_reportsMethod · 0.45

Tested by

no test coverage detected