From 0c907c638071285bd6f9629772901122c1e55ce7 Mon Sep 17 00:00:00 2001 From: Tony Hill Date: Wed, 24 Jun 2026 10:35:47 +0100 Subject: [PATCH] fix: payments add always returns URL, treats browser failure as non-fatal On WSL2 (and other headless environments) xdg-open exits with code 3 because no desktop environment is configured, causing the command to fail with an error even though the URL was already printed to stderr. Always include the URL in the JSON result and return Ok regardless of whether the browser opened, so the user can click or copy the URL in any environment. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- rust/src/payments/mod.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/rust/src/payments/mod.rs b/rust/src/payments/mod.rs index 80d1ec7..55f975b 100644 --- a/rust/src/payments/mod.rs +++ b/rust/src/payments/mod.rs @@ -1,7 +1,5 @@ //! `gddy payments` — payment method management. -use std::io::Write as _; - use cli_engine::{ CliCoreError, CommandResult, CommandSpec, GroupSpec, Module, RuntimeCommandSpec, RuntimeGroupSpec, Tier, @@ -37,19 +35,15 @@ fn add_command() -> RuntimeCommandSpec { |ctx| async move { let env = environments::resolve(&ctx.middleware.env).map_err(map_env_err)?; let url = format!("{}/payment-methods/add-payment?plid=1", env.account_url); - if let Err(e) = open::that(&url) { - let mut stderr = std::io::stderr().lock(); - drop(writeln!( - stderr, - "Failed to open browser. Visit manually:\n {url}" - )); - return Err(CliCoreError::message(format!( - "failed to open browser: {e}" - ))); - } + let opened = open::that(&url).is_ok(); Ok(CommandResult::new(json!({ - "info": "Browser opened to the payment methods management page. \ - Only credit card or Good-as-Gold can be used for domain purchases." + "url": url, + "info": if opened { + "Browser opened. Only credit card or Good-as-Gold can be used for domain purchases." + } else { + "Could not open browser. Visit the URL above to add a payment method. \ + Only credit card or Good-as-Gold can be used for domain purchases." + } }))) }, )