Better handling of invalid route.rs files

This commit is contained in:
Tristan D. 2025-04-17 11:31:29 +02:00
parent c7d4ba974b
commit b7dd6f9379
Signed by: tristan
SSH key fingerprint: SHA256:9oFM1J63hYWJjCnLG6C0fxBS15rwNcWwdQNMOHYKJ/4
3 changed files with 27 additions and 26 deletions

View file

@ -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)
}

View file

@ -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)]

View file

@ -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)]