fix: Return a different error type to distinguish different situations

pull/24376/head
Carol (Nichols || Goulding) 2022-06-02 15:15:25 -04:00
parent a4f51d99f6
commit c7f52ce362
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
1 changed files with 14 additions and 10 deletions

View File

@ -28,6 +28,9 @@ pub enum Error {
#[snafu(display("unsupported column operation on column \"{}\": {}", column_name, msg))] #[snafu(display("unsupported column operation on column \"{}\": {}", column_name, msg))]
UnsupportedColumnOperation { msg: String, column_name: String }, UnsupportedColumnOperation { msg: String, column_name: String },
#[snafu(display("column \"{column_name}\" does not exist"))]
ColumnDoesNotExist { column_name: String },
} }
pub type Result<T, E = Error> = std::result::Result<T, E>; pub type Result<T, E = Error> = std::result::Result<T, E>;
@ -772,9 +775,8 @@ impl MetaData {
} }
}, },
None => { None => {
return UnsupportedColumnOperationSnafu { return ColumnDoesNotExistSnafu {
column_name: expr.column().to_owned(), column_name: expr.column().to_owned(),
msg: "column does not exist",
} }
.fail() .fail()
} }
@ -1768,14 +1770,16 @@ west,host-b,100
); );
// invalid predicate // invalid predicate
assert!(table assert!(matches!(
table
.column_names( .column_names(
&Predicate::new(vec![BinaryExpr::from(("time", ">=", "not a number"))]), &Predicate::new(vec![BinaryExpr::from(("time", ">=", "not a number"))]),
&[], &[],
Selection::All, Selection::All,
dst, dst,
) ),
.is_err()); Err(Error::UnsupportedColumnOperation { column_name, .. }) if column_name == "time",
));
} }
#[test] #[test]