diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-29 17:13:36 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-29 17:13:36 +0800 |
| commit | 6edaa76d67ab1ff211c7cc9cd179ffbefe93a04f (patch) | |
| tree | 02d5b5f68b3d443baccbfc0ed3fc7fa16a3dd9a4 | |
| parent | 05826d67f1f9166a6620475ffdeaa488917befd8 (diff) | |
Rename error types with consistent naming convention
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | examples/example-error-handling/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/example-repl-basic/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/example-unit-test/src/main.rs | 2 | ||||
| -rw-r--r-- | mingling/src/example_docs.rs | 6 | ||||
| -rw-r--r-- | mingling/src/lib.rs | 2 | ||||
| -rw-r--r-- | mingling_core/src/comp.rs | 3 | ||||
| -rw-r--r-- | mingling_core/src/program/collection.rs | 6 | ||||
| -rw-r--r-- | mingling_macros/src/chain.rs | 8 | ||||
| -rw-r--r-- | mingling_macros/src/lib.rs | 50 | ||||
| -rw-r--r-- | mling/src/cli.rs | 4 |
11 files changed, 46 insertions, 42 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 407bcbf..2f4f7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,9 @@ gen_program!(); 7. **\[macros:comp\]** Renamed `CompletionDispatcher` to `CMDCompletion` 8. **\[macros:comp\]** Marked `CompletionContext` and `CompletionSuggest` as `#[doc(hidden)]` +9. **\[macros\]** Renamed `DispatcherNotFound` to `ErrorDispatcherNotFound` +10. **\[macros\]** Renamed `RendererNotFound` to `ErrorRendererNotFound` +11. **\[macros\]** Renamed `EmptyResult` to `ResultEmpty` --- diff --git a/examples/example-error-handling/src/main.rs b/examples/example-error-handling/src/main.rs index d8db852..d4d073e 100644 --- a/examples/example-error-handling/src/main.rs +++ b/examples/example-error-handling/src/main.rs @@ -83,7 +83,7 @@ fn render_error_name_too_long(len: ErrorNameTooLong) { } #[renderer] -fn render_dispatcher_not_found(err: DispatcherNotFound) { +fn render_dispatcher_not_found(err: ErrorDispatcherNotFound) { // Prompt when command is not found, showing the input command r_println!("Command not found: \"{}\"", err.inner.join(" ")); } diff --git a/examples/example-repl-basic/src/main.rs b/examples/example-repl-basic/src/main.rs index f2c871e..630c419 100644 --- a/examples/example-repl-basic/src/main.rs +++ b/examples/example-repl-basic/src/main.rs @@ -166,7 +166,7 @@ fn render_error_directory_not_exist(err: ErrorDirectoryNotExist) { // Handle dispatcher not found event #[renderer] -fn dispatcher_not_found(prev: DispatcherNotFound) { +fn dispatcher_not_found(prev: ErrorDispatcherNotFound) { r_println!("Command not found: \"{}\"", prev.join(", ")) } diff --git a/examples/example-unit-test/src/main.rs b/examples/example-unit-test/src/main.rs index ca7ac25..62c7fbf 100644 --- a/examples/example-unit-test/src/main.rs +++ b/examples/example-unit-test/src/main.rs @@ -110,7 +110,7 @@ fn render_error_name_too_long(len: ErrorNameTooLong) -> String { } #[renderer] -fn render_dispatcher_not_found(err: DispatcherNotFound) { +fn render_dispatcher_not_found(err: ErrorDispatcherNotFound) { r_println!("Command not found: \"{}\"", err.inner.join(" ")); } diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs index 5b889ba..b665485 100644 --- a/mingling/src/example_docs.rs +++ b/mingling/src/example_docs.rs @@ -1029,7 +1029,7 @@ pub mod example_enum_tag {} /// } /// /// #[renderer] -/// fn render_dispatcher_not_found(err: DispatcherNotFound) { +/// fn render_dispatcher_not_found(err: ErrorDispatcherNotFound) { /// // Prompt when command is not found, showing the input command /// r_println!("Command not found: \"{}\"", err.inner.join(" ")); /// } @@ -1658,7 +1658,7 @@ pub mod example_panic_unwind {} /// /// // Handle dispatcher not found event /// #[renderer] -/// fn dispatcher_not_found(prev: DispatcherNotFound) { +/// fn dispatcher_not_found(prev: ErrorDispatcherNotFound) { /// r_println!("Command not found: \"{}\"", prev.join(", ")) /// } /// @@ -1918,7 +1918,7 @@ pub mod example_setup {} /// } /// /// #[renderer] -/// fn render_dispatcher_not_found(err: DispatcherNotFound) { +/// fn render_dispatcher_not_found(err: ErrorDispatcherNotFound) { /// r_println!("Command not found: \"{}\"", err.inner.join(" ")); /// } /// diff --git a/mingling/src/lib.rs b/mingling/src/lib.rs index fee25bc..83fd64e 100644 --- a/mingling/src/lib.rs +++ b/mingling/src/lib.rs @@ -38,7 +38,7 @@ //! } //! //! #[renderer] -//! fn render_dispatcher_not_found(err: DispatcherNotFound) { +//! fn render_dispatcher_not_found(err: ErrorDispatcherNotFound) { //! if err.len() > 0 { //! r_println!("Command not found: [{}]", err.join(" ")); //! } diff --git a/mingling_core/src/comp.rs b/mingling_core/src/comp.rs index 4fb17c7..9d84557 100644 --- a/mingling_core/src/comp.rs +++ b/mingling_core/src/comp.rs @@ -82,7 +82,8 @@ impl CompletionHelper { let suggest = if let Ok(any) = P::dispatch_args_trie(&args) { trace!("entry type: {}", any.member_id); - let dispatcher_not_found = <P::DispatcherNotFound as crate::Groupped<P>>::member_id(); + let dispatcher_not_found = + <P::ErrorDispatcherNotFound as crate::Groupped<P>>::member_id(); if dispatcher_not_found == any.member_id { trace!("begin not Ok"); diff --git a/mingling_core/src/program/collection.rs b/mingling_core/src/program/collection.rs index dec2af6..ff26411 100644 --- a/mingling_core/src/program/collection.rs +++ b/mingling_core/src/program/collection.rs @@ -18,9 +18,9 @@ use crate::{ShellContext, Suggest}; pub trait ProgramCollect { /// Enum type representing internal IDs for the program type Enum; - type DispatcherNotFound: Groupped<Self::Enum>; - type RendererNotFound: Groupped<Self::Enum>; - type EmptyResult: Groupped<Self::Enum>; + type ErrorDispatcherNotFound: Groupped<Self::Enum>; + type ErrorRendererNotFound: Groupped<Self::Enum>; + type ResultEmpty: Groupped<Self::Enum>; /// Use a prefix tree to quickly match arguments and dispatch to an Entry #[cfg(feature = "dispatch_tree")] diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs index 559468c..ac05480 100644 --- a/mingling_macros/src/chain.rs +++ b/mingling_macros/src/chain.rs @@ -95,7 +95,7 @@ fn generate_proc_fn( let body_stmts: &[syn::Stmt] = if is_unit_return && has_resources { let mut stmts = fn_body_stmts.to_vec(); stmts.push(syn::Stmt::Expr( - syn::parse_quote! { crate::EmptyResult::new(()).to_chain() }, + syn::parse_quote! { crate::ResultEmpty::new(()).to_chain() }, None, )); // Box::leak to get a &'static [syn::Stmt] @@ -106,7 +106,7 @@ fn generate_proc_fn( let wrapped_body = wrap_body_with_mut_resources(body_stmts, &mut_resources, program_type); - // When the function returns `()`, wrap the result with EmptyResult + // When the function returns `()`, wrap the result with ResultEmpty let call_or_wrapped = if is_unit_return { if has_resources { quote! { @@ -121,7 +121,7 @@ fn generate_proc_fn( }; quote! { #call - crate::EmptyResult::new(()).to_chain() + crate::ResultEmpty::new(()).to_chain() } } } else if has_resources { @@ -179,7 +179,7 @@ fn generate_original_fn( quote! { { #fn_body - crate::EmptyResult::new(()).to_chain() + crate::ResultEmpty::new(()).to_chain() } } } else { diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index f0ba25b..8cae29f 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -244,7 +244,7 @@ pub fn route(input: TokenStream) -> TokenStream { /// Creates an empty result value wrapped in `ChainProcess` for early return /// from a chain function. /// -/// This macro is a shorthand for constructing an `EmptyResult` and converting +/// This macro is a shorthand for constructing an `ResultEmpty` and converting /// it into a `ChainProcess`, which signals to the pipeline that there is /// no meaningful output to continue processing. /// @@ -273,16 +273,16 @@ pub fn route(input: TokenStream) -> TokenStream { /// /// The macro expands to: /// ```rust,ignore -/// crate::EmptyResult::new(()).to_chain() +/// crate::ResultEmpty::new(()).to_chain() /// ``` /// -/// This works because `EmptyResult` is automatically generated by `gen_program!` +/// This works because `ResultEmpty` is automatically generated by `gen_program!` /// and implements the necessary trait conversions into `ChainProcess`. #[cfg(feature = "extra_macros")] #[proc_macro] pub fn empty_result(_input: TokenStream) -> TokenStream { let expanded = quote! { - crate::EmptyResult::new(()).to_chain() + crate::ResultEmpty::new(()).to_chain() }; TokenStream::from(expanded) } @@ -631,17 +631,17 @@ pub fn chain(attr: TokenStream, item: TokenStream) -> TokenStream { /// /// The macros `gen_program!` automatically generates two fallback types that /// you can provide renderers for: -/// - `RendererNotFound` — triggered when no matching renderer is found -/// - `DispatcherNotFound` — triggered when no matching dispatcher is found +/// - `ErrorRendererNotFound` — triggered when no matching renderer is found +/// - `ErrorDispatcherNotFound` — triggered when no matching dispatcher is found /// /// ```rust,ignore /// #[renderer] -/// fn fallback_dispatcher_not_found(prev: DispatcherNotFound) { +/// fn fallback_dispatcher_not_found(prev: ErrorDispatcherNotFound) { /// r_println!("Unknown command: {}", prev.join(", ")); /// } /// /// #[renderer] -/// fn fallback_renderer_not_found(prev: RendererNotFound) { +/// fn fallback_renderer_not_found(prev: ErrorRendererNotFound) { /// r_println!("No renderer for `{}`", *prev); /// } /// ``` @@ -1046,7 +1046,7 @@ pub fn derive_groupped_serialize(input: TokenStream) -> TokenStream { /// 1. **`pub type Next = ChainProcess<ProgramName>`** — A convenience type alias /// for use in chain function return types. /// 2. **`program_comp_gen!(...)`** (with `comp` feature) — Generates completion infrastructure. -/// 3. **`program_fallback_gen!(...)`** — Generates `RendererNotFound` and `DispatcherNotFound` types. +/// 3. **`program_fallback_gen!(...)`** — Generates `ErrorRendererNotFound` and `ErrorDispatcherNotFound` types. /// 4. **`program_final_gen!(...)`** — Generates the program enum with: /// - An enum with all packed types as variants /// - `Display` implementation for the enum @@ -1258,11 +1258,11 @@ pub fn register_renderer(input: TokenStream) -> TokenStream { /// This macro generates the fallback wrapper types that are essential /// for error handling in the Mingling pipeline: /// -/// - **`RendererNotFound`** — Wraps a `String` (the name of the missing renderer). +/// - **`ErrorRendererNotFound`** — Wraps a `String` (the name of the missing renderer). /// Used when no matching renderer is found for a given output type. -/// - **`DispatcherNotFound`** — Wraps `Vec<String>` (the unrecognized command args). +/// - **`ErrorDispatcherNotFound`** — Wraps `Vec<String>` (the unrecognized command args). /// Used when no matching dispatcher is found for user input. -/// - **`EmptyResult`** — Wraps `()` (the unit type). +/// - **`ResultEmpty`** — Wraps `()` (the unit type). /// Used when the chain returns an empty result. /// /// Users can (and should) write `#[renderer]` functions for these types @@ -1282,18 +1282,18 @@ pub fn register_renderer(input: TokenStream) -> TokenStream { /// # Generated code equivalent /// /// ```rust,ignore -/// pack!(ProgramName, RendererNotFound = String); -/// pack!(ProgramName, DispatcherNotFound = Vec<String>); -/// pack!(ProgramName, EmptyResult = ()); +/// pack!(ProgramName, ErrorRendererNotFound = String); +/// pack!(ProgramName, ErrorDispatcherNotFound = Vec<String>); +/// pack!(ProgramName, ResultEmpty = ()); /// ``` #[proc_macro] pub fn program_fallback_gen(input: TokenStream) -> TokenStream { let name = read_name(&input); let expanded = quote! { - ::mingling::macros::pack!(#name, RendererNotFound = String); - ::mingling::macros::pack!(#name, DispatcherNotFound = Vec<String>); - ::mingling::macros::pack!(#name, EmptyResult = ()); + ::mingling::macros::pack!(#name, ErrorRendererNotFound = String); + ::mingling::macros::pack!(#name, ErrorDispatcherNotFound = Vec<String>); + ::mingling::macros::pack!(#name, ResultEmpty = ()); }; TokenStream::from(expanded) } @@ -1334,7 +1334,7 @@ pub fn program_fallback_gen(input: TokenStream) -> TokenStream { /// /// impl ProgramCollect for MyProgram { /// type Enum = MyProgram; -/// type EmptyResult = EmptyResult; +/// type ResultEmpty = ResultEmpty; /// fn render(any, r) { /* dispatches to all registered renderers */ } /// fn do_chain(any) -> ChainProcess { /* dispatches to all registered chain steps */ } /// fn render_help(any, r) { /* dispatches to all registered help handlers */ } @@ -1506,17 +1506,17 @@ pub fn program_final_gen(input: TokenStream) -> TokenStream { impl ::mingling::ProgramCollect for #name { type Enum = #name; - type DispatcherNotFound = DispatcherNotFound; - type RendererNotFound = RendererNotFound; - type EmptyResult = EmptyResult; + type ErrorDispatcherNotFound = ErrorDispatcherNotFound; + type ErrorRendererNotFound = ErrorRendererNotFound; + type ResultEmpty = ResultEmpty; fn build_renderer_not_found(member_id: Self::Enum) -> ::mingling::AnyOutput<Self::Enum> { - ::mingling::AnyOutput::new(RendererNotFound::new(member_id.to_string())) + ::mingling::AnyOutput::new(ErrorRendererNotFound::new(member_id.to_string())) } fn build_dispatcher_not_found(args: Vec<String>) -> ::mingling::AnyOutput<Self::Enum> { - ::mingling::AnyOutput::new(DispatcherNotFound::new(args)) + ::mingling::AnyOutput::new(ErrorDispatcherNotFound::new(args)) } fn build_empty_result() -> ::mingling::AnyOutput<Self::Enum> { - ::mingling::AnyOutput::new(EmptyResult::new(())) + ::mingling::AnyOutput::new(ResultEmpty::new(())) } ::mingling::__dispatch_program_renderers!( #(#renderer_tokens)* diff --git a/mling/src/cli.rs b/mling/src/cli.rs index 87ba4f0..705c6b4 100644 --- a/mling/src/cli.rs +++ b/mling/src/cli.rs @@ -3,7 +3,7 @@ use mingling::{ setup::{BasicProgramSetup, GeneralRendererSetup}, }; -use crate::{CMDCompletion, DispatcherNotFound, ThisProgram, display::markdown}; +use crate::{CMDCompletion, ErrorDispatcherNotFound, ThisProgram, display::markdown}; pub mod list; pub use list::*; @@ -66,7 +66,7 @@ pub fn cli_entry() { } #[renderer] -pub(crate) fn fallback_disp(prev: DispatcherNotFound) { +pub(crate) fn fallback_disp(prev: ErrorDispatcherNotFound) { r_println!("Error: command \"{}\" not found!", prev.join(" ")); r_println!("Use \"mling --help\" for more information."); } |
