66 DEFAULT_INSTALL_PS1_URL ,
77 DEFAULT_INSTALL_SCRIPT_URL ,
88 defineCommand ,
9+ ExitCode ,
910 getConfigDir ,
1011 getUpdateInstallMethod ,
1112 type InstallMethod ,
@@ -121,8 +122,11 @@ export default defineCommand({
121122 const targetVersion = pinnedVersion ?? ( await resolveLatest ( method , npmPackage ) ) ;
122123
123124 if ( ! targetVersion ) {
124- process . stderr . write ( `${ color . yellow ( "Could not determine the latest version." ) } \n` ) ;
125- return ;
125+ throw new BailianError (
126+ "Could not determine the latest version." ,
127+ ExitCode . GENERAL ,
128+ "Check network access, or pass --to <version>." ,
129+ ) ;
126130 }
127131
128132 if ( targetVersion === currentVersion ) {
@@ -150,14 +154,16 @@ export default defineCommand({
150154 writeUpdateState ( newVer ) ;
151155 updateAgentSkill ( color ) ;
152156 } catch ( error ) {
153- const message = error instanceof Error ? error . message : String ( error ) ;
154157 const reinstall =
155158 error instanceof BailianError && error . hint
156159 ? error . hint . replace ( / ^ R e - r u n : \s * / i, "" )
157160 : binaryReinstallHint ( ) . trim ( ) ;
158- process . stderr . write ( `\nAutomatic binary update failed: ${ message } \n` ) ;
159- process . stderr . write ( "Re-run the install script:\n" ) ;
160- process . stderr . write ( ` ${ reinstall } \n\n` ) ;
161+ throw new BailianError (
162+ "Automatic binary update failed." ,
163+ ExitCode . GENERAL ,
164+ `Re-run the install script:\n ${ reinstall } ` ,
165+ { cause : error } ,
166+ ) ;
161167 }
162168 return ;
163169 }
@@ -179,9 +185,13 @@ export default defineCommand({
179185 process . stderr . write ( `\n${ color . green ( "\u2713 Update complete." ) } \n` ) ;
180186 }
181187 updateAgentSkill ( color ) ;
182- } catch {
183- process . stderr . write ( "\nAutomatic update failed. Please run manually:\n" ) ;
184- process . stderr . write ( ` ${ cmd } \n\n` ) ;
188+ } catch ( error ) {
189+ throw new BailianError (
190+ "Automatic update failed." ,
191+ ExitCode . GENERAL ,
192+ `Please run manually:\n ${ cmd } ` ,
193+ { cause : error } ,
194+ ) ;
185195 }
186196 } ,
187197} ) ;
0 commit comments