fix(derive): keep missing-generation diagnostics author-facing

Replace OUT_DIR/path-shaped proc-macro errors with generated slhx file/module language while preserving the build.rs fix hint.

req: dx/005

req: component/004
This commit is contained in:
slhx agent
2026-06-02 03:54:08 +02:00
parent 998e15758a
commit 20d1159e39
2 changed files with 17 additions and 13 deletions
+9 -13
View File
@@ -12,7 +12,7 @@ pub fn handler(_attr: TokenStream, item: TokenStream) -> TokenStream {
let name = function.sig.ident.to_string(); let name = function.sig.ident.to_string();
let Some(syms_path) = syms_path() else { let Some(syms_path) = syms_path() else {
let message = "#[slhx::handler] requires OUT_DIR; run inside a Cargo crate with slhx_build::app() in build.rs"; let message = "#[slhx::handler] requires generated slhx files; add slhx_build::app().run()? to build.rs or run inside a Cargo crate";
return quote!( return quote!(
#function #function
compile_error!(#message); compile_error!(#message);
@@ -20,10 +20,7 @@ pub fn handler(_attr: TokenStream, item: TokenStream) -> TokenStream {
.into(); .into();
}; };
if !syms_path.exists() { if !syms_path.exists() {
let message = format!( let message = "#[slhx::handler] could not find generated slhx symbols; add slhx_build::app().run()? to build.rs or check template generation";
"#[slhx::handler] could not find {}; add slhx_build::app().run()? to build.rs or check template generation",
syms_path.display()
);
return quote!( return quote!(
#function #function
compile_error!(#message); compile_error!(#message);
@@ -89,7 +86,7 @@ pub fn form(attr: TokenStream, item: TokenStream) -> TokenStream {
let form_name = parse_macro_input!(attr as LitStr).value(); let form_name = parse_macro_input!(attr as LitStr).value();
let form_struct = parse_macro_input!(item as ItemStruct); let form_struct = parse_macro_input!(item as ItemStruct);
let Some(syms_path) = syms_path() else { let Some(syms_path) = syms_path() else {
let message = "#[slhx::form] requires OUT_DIR; run inside a Cargo crate with slhx_build::app() in build.rs"; let message = "#[slhx::form] requires generated slhx files; add slhx_build::app().run()? to build.rs or run inside a Cargo crate";
return quote!( return quote!(
#form_struct #form_struct
compile_error!(#message); compile_error!(#message);
@@ -183,7 +180,7 @@ fn surface_include() -> String {
let Some(path) = generated_path("slhx.generated.rs") else { let Some(path) = generated_path("slhx.generated.rs") else {
return format!( return format!(
" compile_error!({:?}); ", " compile_error!({:?}); ",
"#[slhx::surface] requires OUT_DIR; run inside a Cargo crate with slhx_build::app() in build.rs" "#[slhx::surface] requires generated slhx files; add slhx_build::app().run()? to build.rs or run inside a Cargo crate"
); );
}; };
@@ -193,8 +190,7 @@ fn surface_include() -> String {
format!( format!(
" compile_error!({:?}); ", " compile_error!({:?}); ",
format!( format!(
"#[slhx::surface] could not find {}; add slhx_build::app().run()? to build.rs or check template generation", "#[slhx::surface] could not find generated slhx module; add slhx_build::app().run()? to build.rs or check template generation"
path.display()
) )
) )
} }
@@ -301,10 +297,10 @@ struct GeneratedFormField {
fn form_contract_errors(syms_path: &PathBuf, form_name: &str, form_struct: &ItemStruct) -> Vec<String> { fn form_contract_errors(syms_path: &PathBuf, form_name: &str, form_struct: &ItemStruct) -> Vec<String> {
if !syms_path.exists() { if !syms_path.exists() {
return vec![format!( return vec![
"#[slhx::form] could not find {}; add slhx_build::app().run()? to build.rs or check template generation", "#[slhx::form] could not find generated slhx symbols; add slhx_build::app().run()? to build.rs or check template generation"
syms_path.display() .to_owned(),
)]; ];
} }
let expected = form_fields(syms_path, form_name); let expected = form_fields(syms_path, form_name);
if expected.is_empty() { if expected.is_empty() {
+8
View File
@@ -218,6 +218,10 @@ fn create() -> impl slhx::IntoEffect {
stderr.contains("add slhx_build::app().run()? to build.rs"), stderr.contains("add slhx_build::app().run()? to build.rs"),
"missing build.rs hint in stderr:\n{stderr}" "missing build.rs hint in stderr:\n{stderr}"
); );
assert!(
!stderr.contains("OUT_DIR"),
"diagnostic should not teach Cargo internals:\n{stderr}"
);
} }
#[test] #[test]
@@ -810,6 +814,10 @@ pub mod ui {}
stderr.contains("add slhx_build::app().run()? to build.rs"), stderr.contains("add slhx_build::app().run()? to build.rs"),
"missing build.rs hint in stderr:\n{stderr}" "missing build.rs hint in stderr:\n{stderr}"
); );
assert!(
!stderr.contains("OUT_DIR"),
"diagnostic should not teach Cargo internals:\n{stderr}"
);
} }
#[test] #[test]