diff --git a/crates/pu-cli/src/commands/agent_def.rs b/crates/pu-cli/src/commands/agent_def.rs index d615311..4f183b6 100644 --- a/crates/pu-cli/src/commands/agent_def.rs +++ b/crates/pu-cli/src/commands/agent_def.rs @@ -24,7 +24,7 @@ pub async fn run_list(socket: &Path, json: bool) -> Result<(), CliError> { let project_root = commands::cwd_string()?; let resp = client::send_request(socket, &Request::ListAgentDefs { project_root }).await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -60,7 +60,7 @@ pub async fn run_create( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -76,7 +76,7 @@ pub async fn run_show(socket: &Path, name: &str, json: bool) -> Result<(), CliEr ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -98,7 +98,7 @@ pub async fn run_delete( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/attach.rs b/crates/pu-cli/src/commands/attach.rs index 1fddfa6..e28d552 100644 --- a/crates/pu-cli/src/commands/attach.rs +++ b/crates/pu-cli/src/commands/attach.rs @@ -18,6 +18,6 @@ pub async fn run(socket: &Path, agent_id: &str) -> Result<(), CliError> { ) .await?; let resp = output::check_response(resp, false)?; - output::print_response(&resp, false); + output::print_response(&resp, false)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/clean.rs b/crates/pu-cli/src/commands/clean.rs index 0569472..0c94a69 100644 --- a/crates/pu-cli/src/commands/clean.rs +++ b/crates/pu-cli/src/commands/clean.rs @@ -58,7 +58,7 @@ pub async fn run( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; } } else if let Some(wt_id) = worktree { let resp = client::send_request( @@ -70,7 +70,7 @@ pub async fn run( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; } Ok(()) diff --git a/crates/pu-cli/src/commands/diff.rs b/crates/pu-cli/src/commands/diff.rs index 91dcbf1..97eed74 100644 --- a/crates/pu-cli/src/commands/diff.rs +++ b/crates/pu-cli/src/commands/diff.rs @@ -24,6 +24,6 @@ pub async fn run( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/grid.rs b/crates/pu-cli/src/commands/grid.rs index 3e2ad92..6af6870 100644 --- a/crates/pu-cli/src/commands/grid.rs +++ b/crates/pu-cli/src/commands/grid.rs @@ -28,11 +28,7 @@ pub async fn run(socket: &Path, action: GridAction) -> Result<(), CliError> { match resp { Response::GridLayout { layout } => { if json { - println!( - "{}", - serde_json::to_string_pretty(&layout) - .expect("layout JSON serialization failed") - ); + println!("{}", serde_json::to_string_pretty(&layout)?); } else { print_ascii_grid(&layout); } diff --git a/crates/pu-cli/src/commands/health.rs b/crates/pu-cli/src/commands/health.rs index e639d90..192ced0 100644 --- a/crates/pu-cli/src/commands/health.rs +++ b/crates/pu-cli/src/commands/health.rs @@ -10,6 +10,6 @@ pub async fn run(socket: &Path, json: bool) -> Result<(), CliError> { let resp = client::send_request(socket, &Request::Health).await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/kill.rs b/crates/pu-cli/src/commands/kill.rs index 60c6889..e26020e 100644 --- a/crates/pu-cli/src/commands/kill.rs +++ b/crates/pu-cli/src/commands/kill.rs @@ -56,6 +56,6 @@ pub async fn run( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/logs.rs b/crates/pu-cli/src/commands/logs.rs index bc530c4..c991642 100644 --- a/crates/pu-cli/src/commands/logs.rs +++ b/crates/pu-cli/src/commands/logs.rs @@ -17,6 +17,6 @@ pub async fn run(socket: &Path, agent_id: &str, tail: usize, json: bool) -> Resu ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/prompt.rs b/crates/pu-cli/src/commands/prompt.rs index 6a5b557..56ff059 100644 --- a/crates/pu-cli/src/commands/prompt.rs +++ b/crates/pu-cli/src/commands/prompt.rs @@ -15,7 +15,7 @@ pub async fn run_list(socket: &Path, json: bool) -> Result<(), CliError> { let project_root = commands::cwd_string()?; let resp = client::send_request(socket, &Request::ListTemplates { project_root }).await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; return Ok(()); } @@ -29,10 +29,7 @@ fn run_list_local(json: bool) -> Result<(), CliError> { let templates = template::list_templates(&cwd); if json { - println!( - "{}", - serde_json::to_string_pretty(&templates).expect("templates JSON serialization failed") - ); + println!("{}", serde_json::to_string_pretty(&templates)?); return Ok(()); } @@ -73,7 +70,7 @@ pub async fn run_show(socket: &Path, name: &str, json: bool) -> Result<(), CliEr ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -102,7 +99,7 @@ pub async fn run_create( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -124,6 +121,6 @@ pub async fn run_delete( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/schedule.rs b/crates/pu-cli/src/commands/schedule.rs index 0d06786..57d671b 100644 --- a/crates/pu-cli/src/commands/schedule.rs +++ b/crates/pu-cli/src/commands/schedule.rs @@ -14,7 +14,7 @@ pub async fn run_list(socket: &Path, json: bool) -> Result<(), CliError> { let project_root = commands::cwd_string()?; let resp = client::send_request(socket, &Request::ListSchedules { project_root }).await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -97,7 +97,7 @@ pub async fn run_create( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -113,7 +113,7 @@ pub async fn run_show(socket: &Path, name: &str, json: bool) -> Result<(), CliEr ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -135,7 +135,7 @@ pub async fn run_delete( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -151,7 +151,7 @@ pub async fn run_enable(socket: &Path, name: &str, json: bool) -> Result<(), Cli ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -167,7 +167,7 @@ pub async fn run_disable(socket: &Path, name: &str, json: bool) -> Result<(), Cl ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/spawn.rs b/crates/pu-cli/src/commands/spawn.rs index a0f1892..63c5d8a 100644 --- a/crates/pu-cli/src/commands/spawn.rs +++ b/crates/pu-cli/src/commands/spawn.rs @@ -62,7 +62,7 @@ pub async fn run( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/status.rs b/crates/pu-cli/src/commands/status.rs index 6290065..b1a3228 100644 --- a/crates/pu-cli/src/commands/status.rs +++ b/crates/pu-cli/src/commands/status.rs @@ -19,6 +19,6 @@ pub async fn run(socket: &Path, agent: Option, json: bool) -> Result<(), ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/commands/swarm.rs b/crates/pu-cli/src/commands/swarm.rs index 6ef2279..350fb9d 100644 --- a/crates/pu-cli/src/commands/swarm.rs +++ b/crates/pu-cli/src/commands/swarm.rs @@ -12,7 +12,7 @@ pub async fn run_list(socket: &Path, json: bool) -> Result<(), CliError> { let project_root = commands::cwd_string()?; let resp = client::send_request(socket, &Request::ListSwarmDefs { project_root }).await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -44,7 +44,7 @@ pub async fn run_create( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -87,7 +87,7 @@ pub async fn run_show(socket: &Path, name: &str, json: bool) -> Result<(), CliEr ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -109,7 +109,7 @@ pub async fn run_delete( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } @@ -132,7 +132,7 @@ pub async fn run_run( ) .await?; let resp = output::check_response(resp, json)?; - output::print_response(&resp, json); + output::print_response(&resp, json)?; Ok(()) } diff --git a/crates/pu-cli/src/output.rs b/crates/pu-cli/src/output.rs index da59fa8..adde584 100644 --- a/crates/pu-cli/src/output.rs +++ b/crates/pu-cli/src/output.rs @@ -15,7 +15,7 @@ pub fn check_response(resp: Response, json: bool) -> Result message: message.clone(), }, true, - ); + )?; } Err(CliError::DaemonError { code, message }) } @@ -34,13 +34,10 @@ fn status_colored(status: AgentStatus, exit_code: Option) -> String { } } -pub fn print_response(response: &Response, json_mode: bool) { +pub fn print_response(response: &Response, json_mode: bool) -> Result<(), CliError> { if json_mode { - println!( - "{}", - serde_json::to_string_pretty(response).expect("response JSON serialization failed") - ); - return; + println!("{}", serde_json::to_string_pretty(response)?); + return Ok(()); } match response { Response::HealthReport { @@ -81,7 +78,7 @@ pub fn print_response(response: &Response, json_mode: bool) { Response::StatusReport { worktrees, agents } => { if worktrees.is_empty() && agents.is_empty() { println!("No active agents"); - return; + return Ok(()); } if !agents.is_empty() { println!( @@ -212,10 +209,7 @@ pub fn print_response(response: &Response, json_mode: bool) { println!("Grid subscription active"); } Response::GridLayout { layout } => { - println!( - "{}", - serde_json::to_string_pretty(layout).expect("layout JSON serialization failed") - ); + println!("{}", serde_json::to_string_pretty(layout)?); } Response::GridEvent { project_root, @@ -236,7 +230,7 @@ pub fn print_response(response: &Response, json_mode: bool) { Response::TemplateList { templates } => { if templates.is_empty() { println!("No templates"); - return; + return Ok(()); } println!( "{:<20} {:<12} {:<10} {}", @@ -314,7 +308,7 @@ pub fn print_response(response: &Response, json_mode: bool) { Response::AgentDefList { agent_defs } => { if agent_defs.is_empty() { println!("No agent definitions"); - return; + return Ok(()); } println!( "{:<20} {:<12} {:<10}", @@ -350,7 +344,7 @@ pub fn print_response(response: &Response, json_mode: bool) { Response::SwarmDefList { swarm_defs } => { if swarm_defs.is_empty() { println!("No swarm definitions"); - return; + return Ok(()); } println!( "{:<20} {:<10} {:<10} {}", @@ -399,7 +393,7 @@ pub fn print_response(response: &Response, json_mode: bool) { Response::DiffResult { diffs } => { if diffs.is_empty() { println!("No worktree diffs"); - return; + return Ok(()); } for (i, d) in diffs.iter().enumerate() { if i > 0 { @@ -432,7 +426,7 @@ pub fn print_response(response: &Response, json_mode: bool) { Response::ScheduleList { schedules } => { if schedules.is_empty() { println!("No schedules"); - return; + return Ok(()); } println!( "{:<20} {:<10} {:<10} {:<10} {}", @@ -500,6 +494,7 @@ pub fn print_response(response: &Response, json_mode: bool) { } } } + Ok(()) } #[cfg(test)] @@ -572,7 +567,7 @@ mod tests { fn given_json_mode_should_produce_valid_json() { // Exercise the print_response JSON path (which calls serde internally) let resp = Response::InitResult { created: true }; - print_response(&resp, true); + print_response(&resp, true).unwrap(); // Verify it round-trips through serde correctly let json = serde_json::to_string_pretty(&resp).unwrap(); let parsed: serde_json::Value = serde_json::from_str(&json).unwrap(); @@ -591,17 +586,17 @@ mod tests { projects: vec!["/test".into()], agent_count: 3, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_init_result_created_should_not_panic() { - print_response(&Response::InitResult { created: true }, false); + print_response(&Response::InitResult { created: true }, false).unwrap(); } #[test] fn given_init_result_already_should_not_panic() { - print_response(&Response::InitResult { created: false }, false); + print_response(&Response::InitResult { created: false }, false).unwrap(); } #[test] @@ -611,7 +606,7 @@ mod tests { agent_id: "ag-xyz".into(), status: AgentStatus::Streaming, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -621,7 +616,7 @@ mod tests { agent_id: "ag-xyz".into(), status: AgentStatus::Waiting, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -630,7 +625,7 @@ mod tests { worktrees: vec![], agents: vec![], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -642,7 +637,7 @@ mod tests { make_agent_report("ag-2", AgentStatus::Broken), ], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -674,13 +669,13 @@ mod tests { worktrees: vec![wt], agents: vec![], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_agent_status_should_not_panic() { let resp = Response::AgentStatus(make_agent_report("ag-1", AgentStatus::Waiting)); - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -690,7 +685,7 @@ mod tests { exit_codes: std::collections::HashMap::new(), skipped: vec![], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -698,7 +693,7 @@ mod tests { let resp = Response::SuspendResult { suspended: vec!["ag-1".into()], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -707,7 +702,7 @@ mod tests { agent_id: "ag-1".into(), status: AgentStatus::Streaming, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -716,7 +711,7 @@ mod tests { agent_id: "ag-1".into(), name: "new-name".into(), }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -727,7 +722,7 @@ mod tests { branch_deleted: true, remote_deleted: false, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -736,12 +731,12 @@ mod tests { agent_id: "ag-1".into(), data: "some log output\n".into(), }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_shutting_down_should_not_panic() { - print_response(&Response::ShuttingDown, false); + print_response(&Response::ShuttingDown, false).unwrap(); } #[test] @@ -750,12 +745,12 @@ mod tests { code: "ERR".into(), message: "something failed".into(), }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_ok_response_should_not_panic() { - print_response(&Response::Ok, false); + print_response(&Response::Ok, false).unwrap(); } #[test] @@ -764,7 +759,7 @@ mod tests { agent_id: "ag-1".into(), data: b"hello world".to_vec(), }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -772,12 +767,12 @@ mod tests { let resp = Response::AttachReady { buffered_bytes: 1024, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_grid_subscribed_should_not_panic() { - print_response(&Response::GridSubscribed, false); + print_response(&Response::GridSubscribed, false).unwrap(); } #[test] @@ -785,7 +780,7 @@ mod tests { let resp = Response::GridLayout { layout: serde_json::json!({"root": {"type": "leaf", "id": 1}}), }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -794,12 +789,12 @@ mod tests { project_root: "/test".into(), command: GridCommand::GetLayout, }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_status_subscribed_should_not_panic() { - print_response(&Response::StatusSubscribed, false); + print_response(&Response::StatusSubscribed, false).unwrap(); } #[test] @@ -808,7 +803,7 @@ mod tests { agents: vec![], worktrees: vec![], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } // --- status_colored --- @@ -860,13 +855,13 @@ mod tests { error: None, }], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_empty_diff_result_should_not_panic() { let resp = Response::DiffResult { diffs: vec![] }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -884,7 +879,7 @@ mod tests { error: None, }], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } // --- schedule output --- @@ -909,13 +904,13 @@ mod tests { created_at: chrono::Utc::now(), }], }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] fn given_empty_schedule_list_should_not_panic() { let resp = Response::ScheduleList { schedules: vec![] }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } #[test] @@ -937,6 +932,6 @@ mod tests { agent_name: None, created_at: chrono::Utc::now(), }; - print_response(&resp, false); + print_response(&resp, false).unwrap(); } }