Skip to content

Commit 58811ae

Browse files
committed
graph, store: Do not panic in Entity::try_make on uninterned keys
1 parent 5a065c1 commit 58811ae

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

graph/src/data/store/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,15 @@ impl Entity {
728728
Ok(Entity(obj))
729729
}
730730

731-
pub fn try_make<E, I: TryIntoEntityIterator<E>>(
731+
pub fn try_make<E: std::error::Error + Send + Sync + 'static, I: TryIntoEntityIterator<E>>(
732732
pool: Arc<AtomPool>,
733733
iter: I,
734-
) -> Result<Entity, E> {
734+
) -> Result<Entity, Error> {
735735
let mut obj = Object::new(pool);
736736
for pair in iter {
737737
let (key, value) = pair?;
738-
obj.insert(key, value).expect("key is in AtomPool");
738+
obj.insert(key, value)
739+
.map_err(|e| anyhow!("unknown attribute {}", e.not_interned()))?;
739740
}
740741
Ok(Entity(obj))
741742
}

graph/src/schema/input_schema.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,13 @@ impl Inner {
287287
Entity::make(self.pool.clone(), iter)
288288
}
289289

290-
pub fn try_make_entity<E, I: TryIntoEntityIterator<E>>(&self, iter: I) -> Result<Entity, E> {
290+
pub fn try_make_entity<
291+
E: std::error::Error + Send + Sync + 'static,
292+
I: TryIntoEntityIterator<E>,
293+
>(
294+
&self,
295+
iter: I,
296+
) -> Result<Entity, Error> {
291297
Entity::try_make(self.pool.clone(), iter)
292298
}
293299
}

store/postgres/src/relational_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl FromEntityData for Entity {
254254
schema: &InputSchema,
255255
iter: I,
256256
) -> Result<Self, StoreError> {
257-
schema.try_make_entity(iter)
257+
schema.try_make_entity(iter).map_err(StoreError::from)
258258
}
259259
}
260260

0 commit comments

Comments
 (0)