From bd7d85a03e03ba5bc34f75f320f87f52f75480a1 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 19 Mar 2020 13:42:46 +0100 Subject: [PATCH] use syn:Error for error messages --- sqlx-macros/src/query_macros/output.rs | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/sqlx-macros/src/query_macros/output.rs b/sqlx-macros/src/query_macros/output.rs index 675dd0bf..3a217e92 100644 --- a/sqlx-macros/src/query_macros/output.rs +++ b/sqlx-macros/src/query_macros/output.rs @@ -1,4 +1,4 @@ -use proc_macro2::{Ident, TokenStream}; +use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; use syn::Path; @@ -45,9 +45,9 @@ pub fn columns_to_rust(describe: &Describe) -> crate::Resul let ident = parse_ident(name)?; let type_ = if let Some(type_info) = &column.type_info { - ::return_type_for_id(&type_info) - .ok_or_else(|| { - if let Some(feature_gate) = + ::return_type_for_id(&type_info).map_or_else( + || { + let message = if let Some(feature_gate) = ::get_feature_gate(&type_info) { format!( @@ -68,21 +68,24 @@ pub fn columns_to_rust(describe: &Describe) -> crate::Resul name: column.name.as_deref() } ) - } - })? - .parse::() - .unwrap() - } else { - format!( - "database couldn't tell us the type of {col}; \ - this can happen for columns that are the result of an expression", - col = DisplayColumn { - idx: i, - name: column.name.as_deref() - } + }; + syn::Error::new(Span::call_site(), message).to_compile_error() + }, + |t| t.parse().unwrap(), ) - .parse::() - .unwrap() + } else { + syn::Error::new( + Span::call_site(), + format!( + "database couldn't tell us the type of {col}; \ + this can happen for columns that are the result of an expression", + col = DisplayColumn { + idx: i, + name: column.name.as_deref() + } + ), + ) + .to_compile_error() }; Ok(RustColumn {