Skip to content

Commit

Permalink
graph, store: Do not panic in Entity::try_make on uninterned keys
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Apr 13, 2023
1 parent ef299a6 commit b4363bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions graph/src/data/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,15 @@ impl Entity {
Ok(Entity(obj))
}

pub fn try_make<E, I: TryIntoEntityIterator<E>>(
pub fn try_make<E: std::error::Error + Send + Sync + 'static, I: TryIntoEntityIterator<E>>(
pool: Arc<AtomPool>,
iter: I,
) -> Result<Entity, E> {
) -> Result<Entity, Error> {
let mut obj = Object::new(pool);
for pair in iter {
let (key, value) = pair?;
obj.insert(key, value).expect("key is in AtomPool");
obj.insert(key, value)
.map_err(|e| anyhow!("unknown attribute {}", e.not_interned()))?;
}
Ok(Entity(obj))
}
Expand Down
8 changes: 7 additions & 1 deletion graph/src/schema/input_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ impl Inner {
Entity::make(self.pool.clone(), iter)
}

pub fn try_make_entity<E, I: TryIntoEntityIterator<E>>(&self, iter: I) -> Result<Entity, E> {
pub fn try_make_entity<
E: std::error::Error + Send + Sync + 'static,
I: TryIntoEntityIterator<E>,
>(
&self,
iter: I,
) -> Result<Entity, Error> {
Entity::try_make(self.pool.clone(), iter)
}
}
Expand Down
2 changes: 1 addition & 1 deletion store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl FromEntityData for Entity {
schema: &InputSchema,
iter: I,
) -> Result<Self, StoreError> {
schema.try_make_entity(iter)
schema.try_make_entity(iter).map_err(StoreError::from)
}
}

Expand Down

0 comments on commit b4363bf

Please sign in to comment.