Skip to content

Commit 4b1676d

Browse files
committed
Fix CostModel's error system to match memo trait
1 parent a7065f1 commit 4b1676d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

optd-persistent/src/cost_model/orm.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,13 @@ impl CostModelStorageLayer for BackendManager {
238238
match res {
239239
Ok(insert_res) => insert_res.last_insert_id,
240240
Err(_) => {
241-
return Err(BackendError::BackendError(format!(
242-
"failed to insert statistic {:?} into statistic table",
243-
stat
244-
)))
241+
return Err(BackendError::CostModel(
242+
format!(
243+
"failed to insert statistic {:?} into statistic table",
244+
stat
245+
)
246+
.into(),
247+
))
245248
}
246249
}
247250
}
@@ -450,10 +453,10 @@ impl CostModelStorageLayer for BackendManager {
450453
.collect::<Vec<_>>();
451454

452455
if attr_ids.len() != attr_base_indices.len() {
453-
return Err(BackendError::BackendError(format!(
456+
return Err(BackendError::CostModel(format!(
454457
"Not all attributes found for table_id {} and base indices {:?}",
455458
table_id, attr_base_indices
456-
)));
459+
).into()));
457460
}
458461

459462
self.get_stats_for_attr(attr_ids, stat_type, epoch_id).await
@@ -505,10 +508,10 @@ impl CostModelStorageLayer for BackendManager {
505508
.one(&self.db)
506509
.await?;
507510
if expr_exists.is_none() {
508-
return Err(BackendError::BackendError(format!(
511+
return Err(BackendError::CostModel(format!(
509512
"physical expression id {} not found when storing cost",
510513
physical_expression_id
511-
)));
514+
).into()));
512515
}
513516

514517
// Check if epoch_id exists in Event table
@@ -518,10 +521,10 @@ impl CostModelStorageLayer for BackendManager {
518521
.await
519522
.unwrap();
520523
if epoch_exists.is_none() {
521-
return Err(BackendError::BackendError(format!(
524+
return Err(BackendError::CostModel(format!(
522525
"epoch id {} not found when storing cost",
523526
epoch_id
524-
)));
527+
).into()));
525528
}
526529

527530
let new_cost = plan_cost::ActiveModel {

optd-persistent/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub enum CostModelError {
4747
// TODO: Add more error types
4848
UnknownStatisticType,
4949
VersionedStatisticNotFound,
50+
CustomError(String),
5051
}
5152

5253
/// TODO convert this to `thiserror`
@@ -69,6 +70,12 @@ pub enum BackendError {
6970
// TODO: Add other variants as needed for different error types
7071
}
7172

73+
impl From<String> for CostModelError {
74+
fn from(value: String) -> Self {
75+
CostModelError::CustomError(value)
76+
}
77+
}
78+
7279
impl From<CostModelError> for BackendError {
7380
fn from(value: CostModelError) -> Self {
7481
BackendError::CostModel(value)

0 commit comments

Comments
 (0)