Skip to content

Commit ab02f3f

Browse files
committed
core/translate: Improve error handling in display.rs
1 parent fb1983a commit ab02f3f

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

core/translate/display.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ impl Display for SelectPlan {
120120
}
121121
},
122122
Operation::IndexMethodQuery(query) => {
123-
let index_method = query.index.index_method.as_ref().unwrap();
124-
writeln!(
125-
f,
126-
"{}QUERY INDEX METHOD {}",
127-
indent,
128-
index_method.definition().method_name
129-
)?;
123+
if let Some(index_method) = query.index.index_method.as_ref() {
124+
writeln!(
125+
f,
126+
"{}QUERY INDEX METHOD {}",
127+
indent,
128+
index_method.definition().method_name
129+
)?;
130+
}
130131
}
131132
}
132133
}
@@ -171,13 +172,14 @@ impl Display for DeletePlan {
171172
}
172173
},
173174
Operation::IndexMethodQuery(query) => {
174-
let module = query.index.index_method.as_ref().unwrap();
175-
writeln!(
176-
f,
177-
"{}QUERY MODULE {}",
178-
indent,
179-
module.definition().method_name
180-
)?;
175+
if let Some(module) = query.index.index_method.as_ref() {
176+
writeln!(
177+
f,
178+
"{}QUERY MODULE {}",
179+
indent,
180+
module.definition().method_name
181+
)?;
182+
}
181183
}
182184
}
183185
}
@@ -234,13 +236,14 @@ impl fmt::Display for UpdatePlan {
234236
}
235237
},
236238
Operation::IndexMethodQuery(query) => {
237-
let module = query.index.index_method.as_ref().unwrap();
238-
writeln!(
239-
f,
240-
"{}QUERY MODULE {}",
241-
indent,
242-
module.definition().method_name
243-
)?;
239+
if let Some(module) = query.index.index_method.as_ref() {
240+
writeln!(
241+
f,
242+
"{}QUERY MODULE {}",
243+
indent,
244+
module.definition().method_name
245+
)?;
246+
}
244247
}
245248
}
246249
}
@@ -447,7 +450,10 @@ impl ToTokens for SelectPlan {
447450
s.append(TokenType::TK_JOIN, None)?;
448451
}
449452

450-
let table_ref = self.joined_tables().get(order.original_idx).unwrap();
453+
let table_ref = self
454+
.joined_tables()
455+
.get(order.original_idx)
456+
.expect("table reference not found for join order");
451457
table_ref.to_tokens(s, context)?;
452458
}
453459

@@ -631,14 +637,11 @@ impl ToTokens for UpdatePlan {
631637

632638
s.comma(
633639
self.set_clauses.iter().map(|(col_idx, set_expr)| {
634-
let col_name = table
640+
let col = table
635641
.table
636642
.get_column_at(*col_idx)
637-
.as_ref()
638-
.unwrap()
639-
.name
640-
.as_ref()
641-
.unwrap();
643+
.unwrap_or_else(|| panic!("column at index {} not found", col_idx));
644+
let col_name = col.name.as_ref().expect("column must have a name");
642645

643646
ast::Set {
644647
col_names: vec![ast::Name::exact(col_name.clone())],

0 commit comments

Comments
 (0)