@@ -102,16 +102,21 @@ def install(
102102 repo_url = "https://github.com/Coding-Dev-Tools/devforge-cli.git"
103103 pkg = f"git+{ repo_url } [{ extras } ]"
104104 console .print (f"[yellow]Installing { pkg } ...[/yellow]" )
105+ # Only catch OS-level failures here. A bare `except Exception` would also
106+ # swallow the typer.Exit raised below (typer.Exit subclasses Exception),
107+ # double-printing an error line ("Error: 1") after the failure message.
105108 try :
106- result = subprocess .run ([sys .executable , "-m" , "pip" , "install" , pkg ], capture_output = True , text = True )
107- if result .returncode == 0 :
108- console .print (f"[green]Successfully installed:[/green] { ', ' .join (targets )} " )
109- else :
110- console .print (f"[red]Installation failed:[/red] { result .stderr [:500 ]} " )
111- raise typer .Exit (code = 1 )
112- except Exception as e :
113- console .print (f"[red]Error: { e } [/red]" )
109+ result = subprocess .run (
110+ [sys .executable , "-m" , "pip" , "install" , pkg ], capture_output = True , text = True
111+ )
112+ except OSError as e :
113+ console .print (f"[red]Error running pip:[/red] { e } " )
114114 raise typer .Exit (code = 1 ) from e
115+ if result .returncode == 0 :
116+ console .print (f"[green]Successfully installed:[/green] { ', ' .join (targets )} " )
117+ else :
118+ console .print (f"[red]Installation failed:[/red] { result .stderr [:500 ]} " )
119+ raise typer .Exit (code = 1 )
115120
116121
117122@app .command (name = "versions" )
@@ -188,11 +193,19 @@ def dispatch(ctx: typer.Context):
188193 # `--config file.yaml`) reach the underlying CLI instead of being
189194 # rejected by typer as "No such option".
190195 forwarded = list (ctx .args )
191- result = subprocess .run (
192- [sys .executable , "-m" , module_name ] + forwarded ,
193- capture_output = True ,
194- text = True ,
195- )
196+ try :
197+ result = subprocess .run (
198+ [sys .executable , "-m" , module_name ] + forwarded ,
199+ capture_output = True ,
200+ text = True ,
201+ )
202+ except OSError as e :
203+ console .print (f"[red]Error launching { tool_name } :[/red] { e } " )
204+ raise typer .Exit (code = 1 ) from e
205+ except KeyboardInterrupt :
206+ # Forward Ctrl-C as a conventional 130 exit, not a raw traceback.
207+ console .print ("[yellow]Interrupted.[/yellow]" )
208+ sys .exit (130 )
196209 if result .stdout :
197210 sys .stdout .write (result .stdout )
198211 if result .stderr :
0 commit comments