@@ -73,19 +73,38 @@ export const UpdateCommand = {
7373 prompts . log . info ( `${ Installation . VERSION } → ${ version } ` )
7474
7575 spinner . start ( "Downloading..." )
76- const { data, ext } = await download ( version )
76+ const result = await download ( version ) . catch ( ( e ) => e as Error )
77+ if ( result instanceof Error ) {
78+ spinner . stop ( "Download failed" , 1 )
79+ prompts . log . error ( result . message )
80+ prompts . outro ( "Done" )
81+ return
82+ }
7783 spinner . stop ( "Downloaded" )
7884
79- spinner . start ( "Installing..." )
85+ const spinner2 = prompts . spinner ( )
86+ spinner2 . start ( "Installing..." )
8087 const tmp = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "ocv-" ) )
81- await extract ( data , ext , tmp )
82-
83- const bin = path . join ( tmp , "opencode" )
84- const dest = process . execPath
85- await fs . copyFile ( bin , dest )
86- await fs . chmod ( dest , 0o755 )
87- await fs . rm ( tmp , { recursive : true , force : true } )
88- spinner . stop ( "Installed" )
88+ const err = await ( async ( ) => {
89+ try {
90+ await extract ( result . data , result . ext , tmp )
91+ const bin = path . join ( tmp , "opencode" )
92+ const dest = process . execPath
93+ const staging = dest + ".tmp"
94+ await fs . copyFile ( bin , staging )
95+ await fs . chmod ( staging , 0o755 )
96+ await fs . rename ( staging , dest )
97+ } finally {
98+ await fs . rm ( tmp , { recursive : true , force : true } )
99+ }
100+ } ) ( ) . catch ( ( e ) => e as Error )
101+ if ( err ) {
102+ spinner2 . stop ( "Install failed" , 1 )
103+ prompts . log . error ( err . message )
104+ prompts . outro ( "Done" )
105+ return
106+ }
107+ spinner2 . stop ( "Installed" )
89108
90109 prompts . log . success ( `Updated to ${ version } ` )
91110 prompts . outro ( "Done" )
0 commit comments