Skip to content

Commit

Permalink
Propagate user errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AZWN committed Oct 30, 2024
1 parent 35b4e04 commit 46fe82b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
34 changes: 27 additions & 7 deletions scopegraphs/src/containers/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use futures::future::Shared;
use std::hash::Hash;
use std::rc::Rc;

use super::ResolveOrUserError;

/// Interface for environment containers that support the operations required for query resolution.
pub trait EnvContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>:
From<Env<'sg, LABEL, DATA>> + 'rslv
Expand Down Expand Up @@ -143,6 +145,20 @@ where
}
}

impl<'sg: 'rslv, 'rslv, LABEL: 'sg + Eq, DATA: 'sg + Eq, RE, UE>
Injectable<'sg, 'rslv, LABEL, DATA, Result<bool, RE>>
for Result<Env<'sg, LABEL, DATA>, ResolveOrUserError<RE, UE>>
where
ResolvedPath<'sg, LABEL, DATA>: Hash + Clone,
ResolveOrUserError<RE, UE>: Clone + 'rslv,
{
fn inject_if(data_ok: Result<bool, RE>, path: ResolvedPath<'sg, LABEL, DATA>) -> Self {
data_ok
.map(|ok| if ok { Env::single(path) } else { Env::empty() })
.map_err(|err| ResolveOrUserError::Resolve(err))
}
}

impl<'sg: 'rslv, 'rslv, LABEL: 'sg + Eq, DATA: 'sg + Eq>
Injectable<'sg, 'rslv, LABEL, DATA, FutureWrapper<'rslv, bool>>
for FutureWrapper<'rslv, Env<'sg, LABEL, DATA>>
Expand Down Expand Up @@ -202,16 +218,18 @@ where
}
}

impl<'sg: 'rslv, 'rslv, LABEL: Clone + Eq + 'sg, DATA: Eq + 'sg, E: Clone + 'rslv>
Filterable<'sg, 'rslv, LABEL, DATA, Result<bool, E>> for Result<Env<'sg, LABEL, DATA>, E>
impl<'sg: 'rslv, 'rslv, LABEL: Clone + Eq + 'sg, DATA: Eq + 'sg, RE, UE>
Filterable<'sg, 'rslv, LABEL, DATA, Result<bool, UE>>
for Result<Env<'sg, LABEL, DATA>, ResolveOrUserError<RE, UE>>
where
Env<'sg, LABEL, DATA>: Clone,
ResolvedPath<'sg, LABEL, DATA>: Eq + Hash + Clone,
ResolveOrUserError<RE, UE>: Clone + 'rslv,
{
fn filter(
base_env: &Env<'sg, LABEL, DATA>,
sub_env: &Env<'sg, LABEL, DATA>,
equiv: &'rslv impl DataEquivalence<'sg, DATA, Output = Result<bool, E>>,
equiv: &'rslv impl DataEquivalence<'sg, DATA, Output = Result<bool, UE>>,
) -> Self {
let sub_env = sub_env.clone();
sub_env.into_iter().try_fold(
Expand All @@ -227,10 +245,12 @@ where
equiv.data_equiv(p1.data, p2.data)
}
},
)?;
// p1 is not shadowed, so add it to accumulator
if !shadowed {
filtered_env.insert(p1);
);
match shadowed {
// p1 is not shadowed, so add it to accumulator
Ok(false) => filtered_env.insert(p1),
Ok(true) => {} // ignore
Err(err) => return Err(ResolveOrUserError::User(err)),
}

Ok(filtered_env)
Expand Down
6 changes: 6 additions & 0 deletions scopegraphs/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
//! Using these interfaces, the resolution algorithms can deal with custom behavior introduced
//! by [`Completeness`](crate::completeness::Completeness) implementations.

enum ResolveOrUserError<RE, UE> {
Resolve(RE),
User(UE),
}

mod scope;

pub use scope::*;

mod path;
Expand Down

0 comments on commit 46fe82b

Please sign in to comment.