diff --git a/src/lib.rs b/src/lib.rs index ff0ce6e..8ae8763 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,9 +170,23 @@ impl proptest::strategy::Strategy for ArbStrategy { type Value = A; fn new_tree(&self, runner: &mut TestRunner) -> proptest::strategy::NewTree { - let mut bytes = std::iter::repeat(0u8).take(self.size).collect::>(); - runner.rng().fill_bytes(&mut bytes); - ArbValueTree::new(bytes).map_err(|_| "initial arbitrary call failed".into()) + loop { + let mut bytes = std::iter::repeat(0u8).take(self.size).collect::>(); + runner.rng().fill_bytes(&mut bytes); + match ArbValueTree::new(bytes) { + Ok(v) => { + return Ok(v); + } + Err(e @ arbitrary::Error::IncorrectFormat) => { + // The Arbitrary impl couldn't construct a value + // from the given bytes. Try again. + runner.reject_local(format!("{e}"))?; + } + Err(e) => { + return Err(format!("{e}").into()); + } + } + } } }