-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(expr): introduce ExprError (#3081)
* refactor(expr): introduce ExprError Signed-off-by: TennyZhuang <[email protected]> * fix test Signed-off-by: TennyZhuang <[email protected]> * fix clippy Signed-off-by: TennyZhuang <[email protected]> * prefer to use try_collect Signed-off-by: TennyZhuang <[email protected]>
- Loading branch information
1 parent
4e9090d
commit b0a38c4
Showing
50 changed files
with
536 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2022 Singularity Data | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
pub use anyhow::anyhow; | ||
use risingwave_common::error::{ErrorCode, RwError}; | ||
use risingwave_common::types::DataType; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ExprError { | ||
#[error("Unsupported function: {0}")] | ||
UnsupportedFunction(String), | ||
|
||
#[error("Can't cast {0} to {1}")] | ||
Cast(&'static str, &'static str), | ||
|
||
// TODO: Unify Cast and Cast2. | ||
#[error("Can't cast {0:?} to {1:?}")] | ||
Cast2(DataType, DataType), | ||
|
||
#[error("Out of range")] | ||
NumericOutOfRange, | ||
|
||
#[error("Parse error: {0}")] | ||
Parse(&'static str), | ||
|
||
#[error("Invalid parameter {name}: {reason}")] | ||
InvalidParam { name: &'static str, reason: String }, | ||
|
||
#[error("Array error: {0}")] | ||
Array( | ||
#[backtrace] | ||
#[source] | ||
RwError, | ||
), | ||
|
||
#[error(transparent)] | ||
Internal(#[from] anyhow::Error), | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! ensure { | ||
($cond:expr $(,)?) => { | ||
if !$cond { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!( | ||
stringify!($cond) | ||
))); | ||
} | ||
}; | ||
($cond:expr, $msg:literal $(,)?) => { | ||
if !$cond { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!($msg))); | ||
} | ||
}; | ||
($cond:expr, $err:expr $(,)?) => { | ||
if !$cond { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!$err)); | ||
} | ||
}; | ||
($cond:expr, $fmt:expr, $($arg:tt)*) => { | ||
if !$cond { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!($fmt, $($arg)*))); | ||
} | ||
}; | ||
} | ||
|
||
impl From<ExprError> for RwError { | ||
fn from(s: ExprError) -> Self { | ||
ErrorCode::ExprError(Box::new(s)).into() | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bail { | ||
($msg:literal $(,)?) => { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!($msg))) | ||
}; | ||
($err:expr $(,)?) => { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!($err))) | ||
}; | ||
($fmt:expr, $($arg:tt)*) => { | ||
return Err($crate::ExprError::Internal($crate::error::anyhow!($fmt, $($arg)*))) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.