Skip to content

Commit

Permalink
Make codec::Error more ergonomic (#5216)
Browse files Browse the repository at this point in the history
  • Loading branch information
iosmanthus authored and sre-bot committed Aug 6, 2019
1 parent 053e232 commit 3deaaed
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions components/tidb_query/src/codec/error.rs
Expand Up @@ -3,6 +3,7 @@
use regex::Error as RegexpError;
use serde_json::error::Error as SerdeError;
use std::error::Error as StdError;
use std::fmt::Display;
use std::io;
use std::num::ParseFloatError;
use std::str::Utf8Error;
Expand Down Expand Up @@ -56,12 +57,12 @@ quick_error! {
}

impl Error {
pub fn overflow(data: &str, expr: &str) -> Error {
pub fn overflow(data: impl Display, expr: impl Display) -> Error {
let msg = format!("{} value is out of range in '{}'", data, expr);
Error::Eval(msg, ERR_DATA_OUT_OF_RANGE)
}

pub fn truncated_wrong_val(data_type: &str, val: &str) -> Error {
pub fn truncated_wrong_val(data_type: impl Display, val: impl Display) -> Error {
let msg = format!("Truncated incorrect {} value: '{}'", data_type, val);
Error::Eval(msg, ERR_TRUNCATE_WRONG_VALUE)
}
Expand All @@ -81,7 +82,7 @@ impl Error {
Error::Eval(msg.into(), ERR_UNKNOWN)
}

pub fn invalid_timezone(given_time_zone: &str) -> Error {
pub fn invalid_timezone(given_time_zone: impl Display) -> Error {
let msg = format!("unknown or incorrect time zone: {}", given_time_zone);
Error::Eval(msg, ERR_UNKNOWN_TIMEZONE)
}
Expand Down Expand Up @@ -114,12 +115,12 @@ impl Error {
tikv_util::codec::Error::unexpected_eof().into()
}

pub fn invalid_time_format(val: &str) -> Error {
pub fn invalid_time_format(val: impl Display) -> Error {
let msg = format!("invalid time format: '{}'", val);
Error::Eval(msg, ERR_TRUNCATE_WRONG_VALUE)
}

pub fn incorrect_datetime_value(val: &str) -> Error {
pub fn incorrect_datetime_value(val: impl Display) -> Error {
let msg = format!("Incorrect datetime value: '{}'", val);
Error::Eval(msg, ERR_TRUNCATE_WRONG_VALUE)
}
Expand Down

0 comments on commit 3deaaed

Please sign in to comment.