Better handling of invalid route.rs files
This commit is contained in:
parent
c7d4ba974b
commit
b7dd6f9379
3 changed files with 27 additions and 26 deletions
|
@ -172,15 +172,7 @@ pub fn route_registrations(
|
|||
|
||||
let method_registrations = methods_for_route(route_path);
|
||||
|
||||
if method_registrations.is_empty() {
|
||||
return quote! {
|
||||
compile_error!(concat!(
|
||||
"No routes defined in your route.rs's !\n",
|
||||
"ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)"
|
||||
));
|
||||
};
|
||||
}
|
||||
|
||||
if !method_registrations.is_empty() {
|
||||
let first_method = &method_registrations[0];
|
||||
let first_method_ident = format_ident!("{}", first_method);
|
||||
|
||||
|
@ -203,6 +195,15 @@ pub fn route_registrations(
|
|||
};
|
||||
route_registrations.push(registration);
|
||||
}
|
||||
}
|
||||
if route_registrations.is_empty() {
|
||||
return quote! {
|
||||
compile_error!(concat!(
|
||||
"No routes defined in your route.rs's !\n",
|
||||
"Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)"
|
||||
));
|
||||
};
|
||||
}
|
||||
|
||||
TokenStream::from_iter(route_registrations)
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ use std::{
|
|||
};
|
||||
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream},
|
||||
parse_file,
|
||||
Ident,
|
||||
Item,
|
||||
LitStr,
|
||||
Result,
|
||||
Token,
|
||||
Visibility,
|
||||
parse::{Parse, ParseStream},
|
||||
parse_file,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: No routes defined in your route.rs's !
|
||||
ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)
|
||||
Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)
|
||||
--> tests/failures/no_routes.rs:6:1
|
||||
|
|
||||
6 | #[folder_router("../../../../tests/failures/no_routes", AppState)]
|
||||
|
|
Loading…
Add table
Reference in a new issue