Skip to content

Commit bef126e

Browse files
committed
fix: replace process::exit in doctor
1 parent b865514 commit bef126e

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/commands/doctor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ pub async fn run(args: Args) -> anyhow::Result<()> {
7979
}
8080

8181
if has_fail {
82-
std::process::exit(1);
82+
return Err(
83+
crate::util::output::SilentExit(crate::util::output::exit_code::GENERAL).into(),
84+
);
8385
}
8486

8587
Ok(())

src/commands/init/agents.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use crate::status;
1414

1515
const SKILL_CONTENT: &str = include_str!("../../../skills/steel-browser/SKILL.md");
1616

17+
const CURSOR_DESCRIPTION: &str =
18+
"Steel browser automation CLI for web tasks (scrape, screenshot, interactive browser sessions)";
19+
1720
pub struct DetectedAgent {
1821
pub name: &'static str,
1922
pub install_path: PathBuf,
@@ -70,9 +73,7 @@ pub fn detect_agents() -> Vec<DetectedAgent> {
7073
/// stripping its YAML frontmatter and prepending Cursor-specific frontmatter.
7174
fn cursor_rule_content() -> String {
7275
let body = strip_frontmatter(SKILL_CONTENT);
73-
format!(
74-
"---\ndescription: Steel browser automation CLI for web tasks (scrape, screenshot, interactive browser sessions)\nalwaysApply: false\n---\n\n{body}"
75-
)
76+
format!("---\ndescription: {CURSOR_DESCRIPTION}\nalwaysApply: false\n---\n\n{body}")
7677
}
7778

7879
fn strip_frontmatter(s: &str) -> &str {

src/commands/init/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub async fn run(args: Args) -> anyhow::Result<()> {
2929
// Step 1: login (no-ops if already logged in).
3030
login::run(login::Args {}).await?;
3131

32-
// Step 2: preflight check (calls process::exit on failure).
32+
// Step 2: preflight check.
3333
status!("");
3434
doctor::run(doctor::Args { preflight: true }).await?;
3535

src/util/output.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ pub mod exit_code {
6969
pub const API_SERVER: i32 = 6;
7070
}
7171

72+
/// Sentinel error: the command already printed its own output and reported
73+
/// failure; the process should exit with `code` without printing anything else.
74+
#[derive(Debug)]
75+
pub struct SilentExit(pub i32);
76+
77+
impl std::fmt::Display for SilentExit {
78+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79+
write!(f, "exit {}", self.0)
80+
}
81+
}
82+
83+
impl std::error::Error for SilentExit {}
84+
7285
// --- Pure formatting functions (no I/O) ---
7386

7487
fn format_success(json_mode: bool, data: &Value, text: &str) -> Option<String> {
@@ -172,6 +185,10 @@ pub fn success_text(data: Value) {
172185

173186
/// Format a top-level error for output, then exit. Called from main.
174187
pub fn handle_error(err: &anyhow::Error) -> ! {
188+
if let Some(SilentExit(code)) = err.downcast_ref::<SilentExit>() {
189+
std::process::exit(*code);
190+
}
191+
175192
let (code, error_code, hint) = classify_error(err);
176193
let msg = format!("{err:#}");
177194

0 commit comments

Comments
 (0)