From 10c0b5c7322e746234c51853e77de15f7b8e224b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 25 Feb 2022 22:42:14 +0000 Subject: [PATCH] Check the context before processing values --- lib/src/dbs/channel.rs | 28 ++++++++++++++++------------ lib/src/dbs/iterate.rs | 28 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/src/dbs/channel.rs b/lib/src/dbs/channel.rs index 70a20c68..5c85eaba 100644 --- a/lib/src/dbs/channel.rs +++ b/lib/src/dbs/channel.rs @@ -21,12 +21,14 @@ impl Value { txn: Transaction, chn: UnboundedSender<(Option, Value)>, ) -> Result<(), Error> { - match self { - Value::Array(v) => v.process(&ctx, &opt, &txn, &chn).await?, - Value::Model(v) => v.process(&ctx, &opt, &txn, &chn).await?, - Value::Thing(v) => v.process(&ctx, &opt, &txn, &chn).await?, - Value::Table(v) => v.process(&ctx, &opt, &txn, &chn).await?, - v => chn.send((None, v))?, + if ctx.is_ok() { + match self { + Value::Array(v) => v.process(&ctx, &opt, &txn, &chn).await?, + Value::Model(v) => v.process(&ctx, &opt, &txn, &chn).await?, + Value::Thing(v) => v.process(&ctx, &opt, &txn, &chn).await?, + Value::Table(v) => v.process(&ctx, &opt, &txn, &chn).await?, + v => chn.send((None, v))?, + } } Ok(()) } @@ -42,12 +44,14 @@ impl Array { chn: &UnboundedSender<(Option, Value)>, ) -> Result<(), Error> { for v in self.value.into_iter() { - match v { - Value::Array(v) => v.process(ctx, opt, txn, chn).await?, - Value::Model(v) => v.process(ctx, opt, txn, chn).await?, - Value::Thing(v) => v.process(ctx, opt, txn, chn).await?, - Value::Table(v) => v.process(ctx, opt, txn, chn).await?, - v => chn.send((None, v))?, + if ctx.is_ok() { + match v { + Value::Array(v) => v.process(ctx, opt, txn, chn).await?, + Value::Model(v) => v.process(ctx, opt, txn, chn).await?, + Value::Thing(v) => v.process(ctx, opt, txn, chn).await?, + Value::Table(v) => v.process(ctx, opt, txn, chn).await?, + v => chn.send((None, v))?, + } } } Ok(()) diff --git a/lib/src/dbs/iterate.rs b/lib/src/dbs/iterate.rs index c8fe4138..a10ca462 100644 --- a/lib/src/dbs/iterate.rs +++ b/lib/src/dbs/iterate.rs @@ -23,12 +23,14 @@ impl Value { txn: &Transaction, ite: &mut Iterator<'_>, ) -> Result<(), Error> { - match self { - Value::Array(v) => v.iterate(ctx, opt, txn, ite).await?, - Value::Model(v) => v.iterate(ctx, opt, txn, ite).await?, - Value::Thing(v) => v.iterate(ctx, opt, txn, ite).await?, - Value::Table(v) => v.iterate(ctx, opt, txn, ite).await?, - v => ite.process(ctx, opt, txn, None, v).await, + if ctx.is_ok() { + match self { + Value::Array(v) => v.iterate(ctx, opt, txn, ite).await?, + Value::Model(v) => v.iterate(ctx, opt, txn, ite).await?, + Value::Thing(v) => v.iterate(ctx, opt, txn, ite).await?, + Value::Table(v) => v.iterate(ctx, opt, txn, ite).await?, + v => ite.process(ctx, opt, txn, None, v).await, + } } Ok(()) } @@ -45,12 +47,14 @@ impl Array { ite: &mut Iterator<'_>, ) -> Result<(), Error> { for v in self.value.into_iter() { - match v { - Value::Array(v) => v.iterate(ctx, opt, txn, ite).await?, - Value::Model(v) => v.iterate(ctx, opt, txn, ite).await?, - Value::Thing(v) => v.iterate(ctx, opt, txn, ite).await?, - Value::Table(v) => v.iterate(ctx, opt, txn, ite).await?, - v => ite.process(ctx, opt, txn, None, v).await, + if ctx.is_ok() { + match v { + Value::Array(v) => v.iterate(ctx, opt, txn, ite).await?, + Value::Model(v) => v.iterate(ctx, opt, txn, ite).await?, + Value::Thing(v) => v.iterate(ctx, opt, txn, ite).await?, + Value::Table(v) => v.iterate(ctx, opt, txn, ite).await?, + v => ite.process(ctx, opt, txn, None, v).await, + } } } Ok(())