@@ -21,6 +21,8 @@ use std::process::{Command, Stdio};
2121use std:: sync:: mpsc;
2222use std:: time:: Duration ;
2323
24+ const EMPTY_PLUGIN_NAME_ERROR : & str = "Plugin name cannot be empty" ;
25+
2426// =============================================================================
2527// Plugin SDK Templates (embedded for standalone CLI operation)
2628// =============================================================================
@@ -1063,10 +1065,7 @@ async fn run_list(args: PluginListArgs) -> Result<()> {
10631065}
10641066
10651067async fn run_install ( args : PluginInstallArgs ) -> Result < ( ) > {
1066- // Validate plugin name is not empty (Issue #3700)
1067- if args. name . trim ( ) . is_empty ( ) {
1068- bail ! ( "Plugin name cannot be empty. Please provide a valid plugin name." ) ;
1069- }
1068+ validate_plugin_name_not_empty ( & args. name ) ?;
10701069
10711070 let plugins_dir = get_plugins_dir ( ) ;
10721071
@@ -1264,15 +1263,12 @@ async fn run_show(args: PluginShowArgs) -> Result<()> {
12641263// =============================================================================
12651264
12661265async fn run_new ( args : PluginNewArgs ) -> Result < ( ) > {
1266+ validate_plugin_name_not_empty ( & args. name ) ?;
1267+
12671268 let output_dir = args
12681269 . output
12691270 . unwrap_or_else ( || std:: env:: current_dir ( ) . unwrap_or_default ( ) ) ;
12701271
1271- // Validate plugin name
1272- if args. name . is_empty ( ) {
1273- bail ! ( "Plugin name cannot be empty" ) ;
1274- }
1275-
12761272 if !args
12771273 . name
12781274 . chars ( )
@@ -1376,6 +1372,14 @@ async fn run_new(args: PluginNewArgs) -> Result<()> {
13761372 Ok ( ( ) )
13771373}
13781374
1375+ fn validate_plugin_name_not_empty ( name : & str ) -> Result < ( ) > {
1376+ if name. trim ( ) . is_empty ( ) {
1377+ bail ! ( "{}" , EMPTY_PLUGIN_NAME_ERROR ) ;
1378+ }
1379+
1380+ Ok ( ( ) )
1381+ }
1382+
13791383// =============================================================================
13801384// Dev Command Implementation
13811385// =============================================================================
@@ -2432,6 +2436,31 @@ mod tests {
24322436 assert ! ( args. force, "force should be true" ) ;
24332437 }
24342438
2439+ #[ tokio:: test]
2440+ async fn test_plugin_install_and_new_empty_name_errors_match ( ) {
2441+ let install_error = run_install ( PluginInstallArgs {
2442+ name : String :: new ( ) ,
2443+ version : None ,
2444+ force : false ,
2445+ } )
2446+ . await
2447+ . expect_err ( "empty install plugin name should fail" ) ;
2448+
2449+ let new_error = run_new ( PluginNewArgs {
2450+ name : " " . to_string ( ) ,
2451+ description : "A test plugin" . to_string ( ) ,
2452+ author : None ,
2453+ output : None ,
2454+ advanced : false ,
2455+ typescript : false ,
2456+ } )
2457+ . await
2458+ . expect_err ( "empty new plugin name should fail" ) ;
2459+
2460+ assert_eq ! ( install_error. to_string( ) , EMPTY_PLUGIN_NAME_ERROR ) ;
2461+ assert_eq ! ( new_error. to_string( ) , EMPTY_PLUGIN_NAME_ERROR ) ;
2462+ }
2463+
24352464 // ==========================================================================
24362465 // CLI argument parsing tests - PluginRemoveArgs
24372466 // ==========================================================================
0 commit comments