Repository: gluesql/gluesql
Pull request #238 (2021-06-10 06:37:15)

Remove unnecessary error formatting on expr & value types which impl …
…Debug


Patch:
diff --git a/src/data/value/error.rs b/src/data/value/error.rs
index 2c6ce0b1..6516449e 100644
--- a/src/data/value/error.rs
+++ b/src/data/value/error.rs
@@ -1,12 +1,20 @@
-use {serde::Serialize, std::fmt::Debug, thiserror::Error};
+use {
+    crate::{ast::DataType, data::Value},
+    serde::Serialize,
+    std::fmt::Debug,
+    thiserror::Error,
+};
 
 #[derive(Error, Serialize, Debug, PartialEq)]
 pub enum ValueError {
-    #[error("literal: {literal} is incompatible with data type: {data_type}")]
-    IncompatibleLiteralForDataType { data_type: String, literal: String },
+    #[error("literal: {literal} is incompatible with data type: {data_type:?}")]
+    IncompatibleLiteralForDataType {
+        data_type: DataType,
+        literal: String,
+    },
 
-    #[error("incompatible data type, data type: {data_type}, value: {value}")]
-    IncompatibleDataType { data_type: String, value: String },
+    #[error("incompatible data type, data type: {data_type:#?}, value: {value:#?}")]
+    IncompatibleDataType { data_type: DataType, value: Value },
 
     #[error("null value on not null field")]
     NullValueOnNotNullField,
@@ -23,17 +31,17 @@ pub enum ValueError {
     #[error("failed to parse time: {0}")]
     FailedToParseTime(String),
 
-    #[error("add on non-numeric values: {0} + {1}")]
-    AddOnNonNumeric(String, String),
+    #[error("add on non-numeric values: {0:?} + {1:?}")]
+    AddOnNonNumeric(Value, Value),
 
-    #[error("subtract on non-numeric values: {0} - {1}")]
-    SubtractOnNonNumeric(String, String),
+    #[error("subtract on non-numeric values: {0:?} - {1:?}")]
+    SubtractOnNonNumeric(Value, Value),
 
-    #[error("multiply on non-numeric values: {0} * {1}")]
-    MultiplyOnNonNumeric(String, String),
+    #[error("multiply on non-numeric values: {0:?} * {1:?}")]
+    MultiplyOnNonNumeric(Value, Value),
 
-    #[error("divide on non-numeric values: {0} / {1}")]
-    DivideOnNonNumeric(String, String),
+    #[error("divide on non-numeric values: {0:?} / {1:?}")]
+    DivideOnNonNumeric(Value, Value),
 
     #[error("floating numbers cannot be grouped by")]
     FloatCannotBeGroupedBy,
@@ -70,8 +78,11 @@ pub enum ValueError {
     #[error("unreachable literal cast from number to integer: {0}")]
     UnreachableLiteralCastFromNumberToInteger(String),
 
-    #[error("unimplemented literal cast: {literal} as {data_type}")]
-    UnimplementedLiteralCast { data_type: String, literal: String },
+    #[error("unimplemented literal cast: {literal} as {data_type:?}")]
+    UnimplementedLiteralCast {
+        data_type: DataType,
+        literal: String,
+    },
 
     #[error("unreachable integer overflow: {0}")]
     UnreachableIntegerOverflow(String),
diff --git a/src/data/value/literal.rs b/src/data/value/literal.rs
index 91692bf3..6a3ae86c 100644
--- a/src/data/value/literal.rs
+++ b/src/data/value/literal.rs
@@ -149,7 +149,7 @@ impl Value {
             | (DataType::Time, Literal::Null)
             | (DataType::Interval, Literal::Null) => Ok(Value::Null),
             _ => Err(ValueError::IncompatibleLiteralForDataType {
-                data_type: format!("{:?}", data_type),
+                data_type: data_type.clone(),
                 literal: format!("{:?}", literal),
             }
             .into()),
@@ -203,7 +203,7 @@ impl Value {
             | (DataType::Float, Literal::Null)
             | (DataType::Text, Literal::Null) => Ok(Value::Null),
             _ => Err(ValueError::UnimplementedLiteralCast {
-                data_type: format!("{:?}", data_type),
+                data_type: data_type.clone(),
                 literal: format!("{:?}", literal),
             }
             .into()),
diff --git a/src/data/value/mod.rs b/src/data/value/mod.rs
index 1c888223..1531d864 100644
--- a/src/data/value/mod.rs
+++ b/src/data/value/mod.rs
@@ -92,8 +92,8 @@ impl Value {
 
         if !valid {
             return Err(ValueError::IncompatibleDataType {
-                data_type: format!("{:?}", data_type),
-                value: format!("{:?}", self),
+                data_type: data_type.clone(),
+                value: self.clone(),
             }
             .into());
         }
@@ -164,9 +164,7 @@ impl Value {
             | (Time(_), Null)
             | (Interval(_), Null)
             | (Null, Null) => Ok(Null),
-            _ => Err(
-                ValueError::AddOnNonNumeric(format!("{:?}", self), format!("{:?}", other)).into(),
-            ),
+            _ => Err(ValueError::AddOnNonNumeric(self.clone(), other.clone()).into()),
         }
     }
 
@@ -211,11 +209,7 @@ impl Value {
             | (Time(_), Null)
             | (Interval(_), Null)
             | (Null, Null) => Ok(Null),
-            _ => Err(ValueError::SubtractOnNonNumeric(
-                format!("{:?}", self),
-                format!("{:?}", other),
-            )
-            .into()),
+            _ => Err(ValueError::SubtractOnNonNumeric(self.clone(), other.clone()).into()),
         }
     }
 
@@ -237,11 +231,7 @@ impl Value {
             | (F64(_), Null)
             | (Interval(_), Null)
             | (Null, Null) => Ok(Null),
-            _ => Err(ValueError::MultiplyOnNonNumeric(
-                format!("{:?}", self),
-                format!("{:?}", other),
-            )
-            .into()),
+            _ => Err(ValueError::MultiplyOnNonNumeric(self.clone(), other.clone()).into()),
         }
     }
 
@@ -264,10 +254,7 @@ impl Value {
             | (F64(_), Null)
             | (Interval(_), Null)
             | (Null, Null) => Ok(Null),
-            _ => Err(
-                ValueError::DivideOnNonNumeric(format!("{:?}", self), format!("{:?}", other))
-                    .into(),
-            ),
+            _ => Err(ValueError::DivideOnNonNumeric(self.clone(), other.clone()).into()),
         }
     }
 
diff --git a/src/executor/aggregate/error.rs b/src/executor/aggregate/error.rs
index e6b6c4f1..f73b4a59 100644
--- a/src/executor/aggregate/error.rs
+++ b/src/executor/aggregate/error.rs
@@ -1,11 +1,9 @@
-use serde::Serialize;
-use std::fmt::Debug;
-use thiserror::Error;
+use {crate::ast::Expr, serde::Serialize, std::fmt::Debug, thiserror::Error};
 
 #[derive(Error, Serialize, Debug, PartialEq)]
 pub enum AggregateError {
-    #[error("unsupported compound identifier: {0}")]
-    UnsupportedCompoundIdentifier(String),
+    #[error("unsupported compound identifier: {0:#?}")]
+    UnsupportedCompoundIdentifier(Expr),
 
     #[error("unsupported aggregation: {0}")]
     UnsupportedAggregation(String),
diff --git a/src/executor/aggregate/mod.rs b/src/executor/aggregate/mod.rs
index f8cfc3c0..220dc8cf 100644
--- a/src/executor/aggregate/mod.rs
+++ b/src/executor/aggregate/mod.rs
@@ -171,10 +171,7 @@ fn aggregate<'a>(
             .ok_or_else(|| AggregateError::ValueNotFound(ident.to_string())),
         Expr::CompoundIdentifier(idents) => {
             if idents.len() != 2 {
-                return Err(AggregateError::UnsupportedCompoundIdentifier(format!(
-                    "{:?}",
-                    expr
-                )));
+                return Err(AggregateError::UnsupportedCompoundIdentifier(expr.clone()));
             }
 
             let table_alias = &idents[0];
diff --git a/src/executor/alter/error.rs b/src/executor/alter/error.rs
index 33bd577b..3aded435 100644
--- a/src/executor/alter/error.rs
+++ b/src/executor/alter/error.rs
@@ -1,4 +1,9 @@
-use {serde::Serialize, std::fmt::Debug, thiserror::Error};
+use {
+    crate::ast::{DataType, Expr},
+    serde::Serialize,
+    std::fmt::Debug,
+    thiserror::Error,
+};
 
 #[derive(Error, Serialize, Debug, PartialEq)]
 pub enum AlterError {
@@ -11,13 +16,13 @@ pub enum AlterError {
     TableNotFound(String),
 
     // validate column def
-    #[error("column '{0}' of data type '{1}' is unsupported for unique constraint")]
-    UnsupportedDataTypeForUniqueColumn(String, String),
+    #[error("column '{0}' of data type '{1:?}' is unsupported for unique constraint")]
+    UnsupportedDataTypeForUniqueColumn(String, DataType),
 
     // validate index expr
-    #[error("unsupported index expr: {0}")]
-    UnsupportedIndexExpr(String),
+    #[error("unsupported index expr: {0:#?}")]
+    UnsupportedIndexExpr(Expr),
 
-    #[error("identifier not found: {0}")]
-    IdentifierNotFound(String),
+    #[error("identifier not found: {0:#?}")]
+    IdentifierNotFound(Expr),
 }
diff --git a/src/executor/alter/index.rs b/src/executor/alter/index.rs
index 63192909..243034de 100644
--- a/src/executor/alter/index.rs
+++ b/src/executor/alter/index.rs
@@ -31,9 +31,9 @@ pub async fn create_index<T: 'static + Debug, U: GStore<T> + GStoreMut<T>>(
 
         let (valid, has_ident) = validate_index_expr(&columns, expr);
         if !valid {
-            return Err(AlterError::UnsupportedIndexExpr(format!("{:#?}", expr)).into());
+            return Err(AlterError::UnsupportedIndexExpr(expr.clone()).into());
         } else if !has_ident {
-            return Err(AlterError::IdentifierNotFound(format!("{:#?}", expr)).into());
+            return Err(AlterError::IdentifierNotFound(expr.clone()).into());
         }
 
         Ok((table_name, index_name))
diff --git a/src/executor/alter/validate.rs b/src/executor/alter/validate.rs
index 36db62d6..3f1791ba 100644
--- a/src/executor/alter/validate.rs
+++ b/src/executor/alter/validate.rs
@@ -23,7 +23,7 @@ pub fn validate(column_def: &ColumnDef) -> Result<()> {
     {
         return Err(AlterError::UnsupportedDataTypeForUniqueColumn(
             name.to_string(),
-            format!("{:?}", data_type),
+            data_type.clone(),
         )
         .into());
     }
diff --git a/src/executor/evaluate/error.rs b/src/executor/evaluate/error.rs
index e4831604..dda8d598 100644
--- a/src/executor/evaluate/error.rs
+++ b/src/executor/evaluate/error.rs
@@ -31,8 +31,8 @@ pub enum EvaluateError {
     #[error("only boolean value is accepted: {0}")]
     BooleanTypeRequired(String),
 
-    #[error("unsupported compound identifier {0}")]
-    UnsupportedCompoundIdentifier(String),
+    #[error("unsupported compound identifier {0:#?}")]
+    UnsupportedCompoundIdentifier(Expr),
 
     #[error("unreachable wildcard expression")]
     UnreachableWildcardExpr,
diff --git a/src/executor/evaluate/mod.rs b/src/executor/evaluate/mod.rs
index 3a7c8bbe..ed4e011b 100644
--- a/src/executor/evaluate/mod.rs
+++ b/src/executor/evaluate/mod.rs
@@ -56,9 +56,7 @@ pub async fn evaluate<'a, T: 'static + Debug>(
         Expr::Nested(expr) => eval(&expr).await,
         Expr::CompoundIdentifier(idents) => {
             if idents.len() != 2 {
-                return Err(
-                    EvaluateError::UnsupportedCompoundIdentifier(format!("{:?}", expr)).into(),
-                );
+                return Err(EvaluateError::UnsupportedCompoundIdentifier(expr.clone()).into());
             }
 
             let table_alias = &idents[0];
diff --git a/src/executor/validate.rs b/src/executor/validate.rs
index 919a97fc..2431417a 100644
--- a/src/executor/validate.rs
+++ b/src/executor/validate.rs
@@ -19,8 +19,8 @@ pub enum ValidateError {
     #[error("conflict! storage row has no column on index {0}")]
     ConflictOnStorageColumnIndex(usize),
 
-    #[error("duplicate entry '{0}' for unique column '{1}'")]
-    DuplicateEntryOnUniqueField(String, String),
+    #[error("duplicate entry '{0:?}' for unique column '{1}'")]
+    DuplicateEntryOnUniqueField(Value, String),
 }
 
 pub enum ColumnValidation {
@@ -78,7 +78,7 @@ impl UniqueConstraint {
                 || Some(new_key),
                 || {
                     ValidateError::DuplicateEntryOnUniqueField(
-                        format!("{:?}", value),
+                        value.clone(),
                         self.column_name.to_owned(),
                     )
                     .into()
diff --git a/src/storages/sled_storage/alter_table.rs b/src/storages/sled_storage/alter_table.rs
index b6617835..e6ed2e8c 100644
--- a/src/storages/sled_storage/alter_table.rs
+++ b/src/storages/sled_storage/alter_table.rs
@@ -163,7 +163,7 @@ impl AlterTable for SledStorage {
             (None, false) => {
                 return Err((
                     self,
-                    AlterTableError::DefaultValueRequired(format!("{:?}", column_def)).into(),
+                    AlterTableError::DefaultValueRequired(column_def.clone()).into(),
                 ));
             }
         };
diff --git a/src/store/alter_table.rs b/src/store/alter_table.rs
index 99b8c5e4..7dca69d3 100644
--- a/src/store/alter_table.rs
+++ b/src/store/alter_table.rs
@@ -14,8 +14,8 @@ pub enum AlterTableError {
     #[error("Renaming column not found")]
     RenamingColumnNotFound,
 
-    #[error("Default value is required: {0}")]
-    DefaultValueRequired(String),
+    #[error("Default value is required: {0:#?}")]
+    DefaultValueRequired(ColumnDef),
 
     #[error("Adding column already exists: {0}")]
     AddingColumnAlreadyExists(String),


Test patch:
diff --git a/src/tests/aggregate.rs b/src/tests/aggregate.rs
index 8b98c06f..74380c82 100644
--- a/src/tests/aggregate.rs
+++ b/src/tests/aggregate.rs
@@ -65,15 +65,7 @@ test_case!(aggregate, async move {
 
     let error_cases = vec![
         (
-            AggregateError::UnsupportedCompoundIdentifier(format!(
-                "{:?}",
-                ast::Expr::CompoundIdentifier(vec![
-                    "id".to_owned(),
-                    "name".to_owned(),
-                    "ok".to_owned()
-                ])
-            ))
-            .into(),
+            AggregateError::UnsupportedCompoundIdentifier(expr!("id.name.ok")).into(),
             "SELECT SUM(id.name.ok) FROM Item;",
         ),
         (
diff --git a/src/tests/alter/alter_table.rs b/src/tests/alter/alter_table.rs
index f2a6e4bf..6e27f357 100644
--- a/src/tests/alter/alter_table.rs
+++ b/src/tests/alter/alter_table.rs
@@ -41,14 +41,11 @@ test_case!(alter_table_add_drop, async move {
         ("SELECT * FROM Foo;", Ok(select!(id; I64; 1; 2))),
         (
             "ALTER TABLE Foo ADD COLUMN amount INTEGER",
-            Err(AlterTableError::DefaultValueRequired(format!(
-                "{:?}",
-                ColumnDef {
-                    name: "amount".to_owned(),
-                    data_type: DataType::Int,
-                    options: vec![]
-                }
-            ))
+            Err(AlterTableError::DefaultValueRequired(ColumnDef {
+                name: "amount".to_owned(),
+                data_type: DataType::Int,
+                options: vec![],
+            })
             .into()),
         ),
         (
@@ -102,7 +99,7 @@ test_case!(alter_table_add_drop, async move {
             "ALTER TABLE Foo ADD COLUMN something FLOAT UNIQUE",
             Err(AlterError::UnsupportedDataTypeForUniqueColumn(
                 "something".to_owned(),
-                format!("{:?}", DataType::Float),
+                DataType::Float,
             )
             .into()),
         ),
diff --git a/src/tests/alter/create_table.rs b/src/tests/alter/create_table.rs
index af78ee50..3c20eb24 100644
--- a/src/tests/alter/create_table.rs
+++ b/src/tests/alter/create_table.rs
@@ -56,7 +56,7 @@ test_case!(create_table, async move {
         )"#,
             Err(AlterError::UnsupportedDataTypeForUniqueColumn(
                 "ratio".to_owned(),
-                format!("{:?}", ast::DataType::Float),
+                ast::DataType::Float,
             )
             .into()),
         ),
diff --git a/src/tests/alter/drop_indexed_column.rs b/src/tests/alter/drop_indexed_column.rs
index 1cea65a0..30002377 100644
--- a/src/tests/alter/drop_indexed_column.rs
+++ b/src/tests/alter/drop_indexed_column.rs
@@ -21,10 +21,7 @@ CREATE TABLE Test (
     "#
     );
 
-    use {
-        ast::{AstLiteral, Expr, IndexOperator::*},
-        Value::*,
-    };
+    use {ast::IndexOperator::*, Value::*};
 
     // create indexes
     run!("CREATE INDEX idx_name ON Test (num + 1)");
@@ -36,11 +33,7 @@ CREATE TABLE Test (
 
     // check indexes working
     test!(
-        Err(AlterError::IdentifierNotFound(format!(
-            "{:#?}",
-            Expr::Literal(AstLiteral::Number("100".to_owned()))
-        ))
-        .into()),
+        Err(AlterError::IdentifierNotFound(expr!("100")).into()),
         "CREATE INDEX idx_literal ON Test (100)"
     );
 
diff --git a/src/tests/arithmetic.rs b/src/tests/arithmetic.rs
index 64c6401f..71f3fc4d 100644
--- a/src/tests/arithmetic.rs
+++ b/src/tests/arithmetic.rs
@@ -61,35 +61,19 @@ test_case!(arithmetic, async move {
 
     let test_cases = vec![
         (
-            ValueError::AddOnNonNumeric(
-                format!("{:?}", Value::Str("A".to_owned())),
-                format!("{:?}", Value::I64(1)),
-            )
-            .into(),
+            ValueError::AddOnNonNumeric(Value::Str("A".to_owned()), Value::I64(1)).into(),
             "SELECT * FROM Arith WHERE name + id < 1",
         ),
         (
-            ValueError::SubtractOnNonNumeric(
-                format!("{:?}", Value::Str("A".to_owned())),
-                format!("{:?}", Value::I64(1)),
-            )
-            .into(),
+            ValueError::SubtractOnNonNumeric(Value::Str("A".to_owned()), Value::I64(1)).into(),
             "SELECT * FROM Arith WHERE name - id < 1",
         ),
         (
-            ValueError::MultiplyOnNonNumeric(
-                format!("{:?}", Value::Str("A".to_owned())),
-                format!("{:?}", Value::I64(1)),
-            )
-            .into(),
+            ValueError::MultiplyOnNonNumeric(Value::Str("A".to_owned()), Value::I64(1)).into(),
             "SELECT * FROM Arith WHERE name * id < 1",
         ),
         (
-            ValueError::DivideOnNonNumeric(
-                format!("{:?}", Value::Str("A".to_owned())),
-                format!("{:?}", Value::I64(1)),
-            )
-            .into(),
+            ValueError::DivideOnNonNumeric(Value::Str("A".to_owned()), Value::I64(1)).into(),
             "SELECT * FROM Arith WHERE name / id < 1",
         ),
         (
diff --git a/src/tests/function/cast.rs b/src/tests/function/cast.rs
index 797ac781..0f44701b 100644
--- a/src/tests/function/cast.rs
+++ b/src/tests/function/cast.rs
@@ -85,7 +85,7 @@ test_case!(cast_literal, async move {
         (
             r#"SELECT CAST(NULL AS INTERVAL) FROM Item"#,
             Err(ValueError::UnimplementedLiteralCast {
-                data_type: format!("{:?}", ast::DataType::Interval),
+                data_type: ast::DataType::Interval,
                 literal: format!("{:?}", data::Literal::Null),
             }
             .into()),
diff --git a/src/tests/index/basic.rs b/src/tests/index/basic.rs
index a4c620be..388b100e 100644
--- a/src/tests/index/basic.rs
+++ b/src/tests/index/basic.rs
@@ -278,11 +278,7 @@ CREATE TABLE Test (
     );
 
     test!(
-        Err(AlterError::UnsupportedIndexExpr(format!(
-            "{:#?}",
-            ast::Expr::CompoundIdentifier(vec!["a".to_owned(), "b".to_owned()])
-        ))
-        .into()),
+        Err(AlterError::UnsupportedIndexExpr(expr!("a.b")).into()),
         "CREATE INDEX idx_wow On Test (a.b)"
     );
 
diff --git a/src/tests/index/expr.rs b/src/tests/index/expr.rs
index 13b2f504..8a405f10 100644
--- a/src/tests/index/expr.rs
+++ b/src/tests/index/expr.rs
@@ -19,10 +19,7 @@ CREATE TABLE Test (
     "#
     );
 
-    use {
-        ast::{AstLiteral, Expr, IndexOperator::*},
-        Value::*,
-    };
+    use {ast::IndexOperator::*, Value::*};
 
     test!(Ok(Payload::CreateIndex), "CREATE INDEX idx_id ON Test (id)");
 
@@ -47,11 +44,7 @@ CREATE TABLE Test (
     );
 
     test!(
-        Err(AlterError::IdentifierNotFound(format!(
-            "{:#?}",
-            Expr::Literal(AstLiteral::Number("100".to_owned()))
-        ))
-        .into()),
+        Err(AlterError::IdentifierNotFound(expr!("100")).into()),
         "CREATE INDEX idx_literal ON Test (100)"
     );
 
diff --git a/src/tests/migrate.rs b/src/tests/migrate.rs
index d11e55e0..540533ab 100644
--- a/src/tests/migrate.rs
+++ b/src/tests/migrate.rs
@@ -1,4 +1,4 @@
-use crate::{ast::Expr, *};
+use crate::*;
 
 test_case!(migrate, async move {
     run!(
@@ -29,15 +29,7 @@ test_case!(migrate, async move {
             "INSERT INTO Test (id, num, name) VALUES (1, 1, a.b);",
         ),
         (
-            EvaluateError::UnsupportedCompoundIdentifier(format!(
-                "{:?}",
-                Expr::CompoundIdentifier(vec![
-                    "Here".to_owned(),
-                    "User".to_owned(),
-                    "id".to_owned()
-                ])
-            ))
-            .into(),
+            EvaluateError::UnsupportedCompoundIdentifier(expr!("Here.User.id")).into(),
             "SELECT * FROM Test WHERE Here.User.id = 1",
         ),
         (
diff --git a/src/tests/validate/types.rs b/src/tests/validate/types.rs
index 4df4becf..130f0cbe 100644
--- a/src/tests/validate/types.rs
+++ b/src/tests/validate/types.rs
@@ -1,4 +1,8 @@
-use {crate::ast::DataType, crate::*, std::borrow::Cow};
+use {
+    crate::ast::DataType,
+    crate::{data::Literal, *},
+    std::borrow::Cow,
+};
 
 test_case!(types, async move {
     run!("CREATE TABLE TableB (id BOOLEAN);");
@@ -10,16 +14,16 @@ test_case!(types, async move {
         (
             "INSERT INTO TableB SELECT uid FROM TableC;",
             Err(ValueError::IncompatibleDataType {
-                data_type: format!("{:?}", DataType::Boolean),
-                value: format!("{:?}", Value::I64(1)),
+                data_type: DataType::Boolean,
+                value: Value::I64(1),
             }
             .into()),
         ),
         (
             "INSERT INTO TableC (uid) VALUES (\"A\")",
             Err(ValueError::IncompatibleLiteralForDataType {
-                data_type: format!("{:?}", DataType::Int),
-                literal: format!("{:?}", data::Literal::Text(Cow::Owned("A".to_owned()))),
+                data_type: DataType::Int,
+                literal: format!("{:?}", Literal::Text(Cow::Owned("A".to_owned()))),
             }
             .into()),
         ),
@@ -34,16 +38,16 @@ test_case!(types, async move {
         (
             "UPDATE TableC SET uid = TRUE;",
             Err(ValueError::IncompatibleLiteralForDataType {
-                data_type: format!("{:?}", DataType::Int),
-                literal: format!("{:?}", data::Literal::Boolean(true)),
+                data_type: DataType::Int,
+                literal: format!("{:?}", Literal::Boolean(true)),
             }
             .into()),
         ),
         (
             "UPDATE TableC SET uid = (SELECT id FROM TableB LIMIT 1) WHERE uid = 1",
             Err(ValueError::IncompatibleDataType {
-                data_type: format!("{:?}", DataType::Int),
-                value: format!("{:?}", Value::Bool(false)),
+                data_type: DataType::Int,
+                value: Value::Bool(false),
             }
             .into()),
         ),
diff --git a/src/tests/validate/unique.rs b/src/tests/validate/unique.rs
index 7c214ae5..faa9b4c3 100644
--- a/src/tests/validate/unique.rs
+++ b/src/tests/validate/unique.rs
@@ -38,83 +38,43 @@ CREATE TABLE TestC (
 
     let error_cases = vec![
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(2)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(2), "id".to_owned()).into(),
             "INSERT INTO TestA VALUES (2, 2)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(4)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(4), "id".to_owned()).into(),
             "INSERT INTO TestA VALUES (4, 4), (4, 5)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(2)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(2), "id".to_owned()).into(),
             "UPDATE TestA SET id = 2 WHERE id = 1",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(1)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(1), "id".to_owned()).into(),
             "INSERT INTO TestB VALUES (1, 3)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(2)),
-                "num".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(2), "num".to_owned()).into(),
             "INSERT INTO TestB VALUES (4, 2)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(5)),
-                "num".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(5), "num".to_owned()).into(),
             "INSERT INTO TestB VALUES (5, 5), (6, 5)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(2)),
-                "num".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(2), "num".to_owned()).into(),
             "UPDATE TestB SET num = 2 WHERE id = 1",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(2)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(2), "id".to_owned()).into(),
             "INSERT INTO TestC VALUES (2, 4)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(3)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(3), "id".to_owned()).into(),
             "INSERT INTO TestC VALUES (NULL, 5), (3, 5), (3, 6)",
         ),
         (
-            ValidateError::DuplicateEntryOnUniqueField(
-                format!("{:?}", Value::I64(1)),
-                "id".to_owned(),
-            )
-            .into(),
+            ValidateError::DuplicateEntryOnUniqueField(Value::I64(1), "id".to_owned()).into(),
             "UPDATE TestC SET id = 1",
         ),
     ];