From 5bf05d545e10d656df895325483e2c46a5437f69 Mon Sep 17 00:00:00 2001 From: Salman Mohammed Date: Thu, 27 Feb 2025 18:18:38 -0500 Subject: [PATCH] fix: return tool error for invalid param in computer controller (#1430) --- crates/goose-mcp/src/computercontroller/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/goose-mcp/src/computercontroller/mod.rs b/crates/goose-mcp/src/computercontroller/mod.rs index be74395b72..9dd2a5e19f 100644 --- a/crates/goose-mcp/src/computercontroller/mod.rs +++ b/crates/goose-mcp/src/computercontroller/mod.rs @@ -501,7 +501,12 @@ impl ComputerControllerRouter { })?; (bytes.to_vec(), "bin") } - _ => unreachable!(), // Prevented by enum in tool definition + _ => { + return Err(ToolError::InvalidParameters(format!( + "Invalid 'save_as' parameter: {}. Valid options are: 'text', 'json', 'binary'", + save_as + ))); + } }; // Save to cache @@ -571,7 +576,11 @@ impl ComputerControllerRouter { script_path.display() ) } - _ => unreachable!(), // Prevented by enum in tool definition + _ => { + return Err( ToolError::InvalidParameters( + format!("Invalid 'language' parameter: {}. Valid options are: 'shell', 'batch', 'ruby', 'powershell", language) + )); + } }; // Run the script @@ -712,7 +721,10 @@ impl ComputerControllerRouter { Ok(vec![Content::text("Cache cleared successfully.")]) } - _ => unreachable!(), // Prevented by enum in tool definition + _ => Err(ToolError::InvalidParameters(format!( + "Invalid 'command' parameter: {}. Valid options are: 'list', 'view', 'delete', 'clear'", + command + ))) } } }