diff --git a/query-engine/driver-adapters/src/proxy.rs b/query-engine/driver-adapters/src/proxy.rs index 62086a245199..a708d75c0e32 100644 --- a/query-engine/driver-adapters/src/proxy.rs +++ b/query-engine/driver-adapters/src/proxy.rs @@ -249,6 +249,12 @@ fn js_value_to_quaint( column_type: ColumnType, column_name: &str, ) -> quaint::Result> { + let parse_number_as_i64 = |n: &serde_json::Number| { + n.as_i64().ok_or(conversion_error!( + "number must be an integer in column '{column_name}', got '{n}'" + )) + }; + // Note for the future: it may be worth revisiting how much bloat so many panics with different static // strings add to the compiled artefact, and in case we should come up with a restricted set of panic // messages, or even find a way of removing them altogether. @@ -256,8 +262,7 @@ fn js_value_to_quaint( ColumnType::Int32 => match json_value { serde_json::Value::Number(n) => { // n.as_i32() is not implemented, so we need to downcast from i64 instead - n.as_i64() - .ok_or(conversion_error!("number must be an integer in column '{column_name}'")) + parse_number_as_i64(&n) .and_then(|n| -> quaint::Result { n.try_into() .map_err(|e| conversion_error!("cannot convert {n} to i32 in column '{column_name}': {e}")) @@ -273,9 +278,7 @@ fn js_value_to_quaint( )), }, ColumnType::Int64 => match json_value { - serde_json::Value::Number(n) => n.as_i64().map(QuaintValue::int64).ok_or(conversion_error!( - "number must be an i64 in column '{column_name}', got {n}" - )), + serde_json::Value::Number(n) => parse_number_as_i64(&n).map(QuaintValue::int64), serde_json::Value::String(s) => s.parse::().map(QuaintValue::int64).map_err(|e| { conversion_error!("string-encoded number must be an i64 in column '{column_name}', got {s}: {e}") }),