@@ -23,6 +23,7 @@ import type { SentryTeam } from "../../types/index.js";
2323import { createTeam , listTeams } from "../api-client.js" ;
2424import { formatBanner } from "../banner.js" ;
2525import { CLI_VERSION } from "../constants.js" ;
26+ import { WizardError } from "../errors.js" ;
2627import { getAuthToken } from "../db/auth.js" ;
2728import { terminalLink } from "../formatters/colors.js" ;
2829import { getSentryBaseUrl } from "../sentry-urls.js" ;
@@ -326,11 +327,10 @@ async function preamble(
326327 dryRun : boolean
327328) : Promise < boolean > {
328329 if ( ! ( yes || process . stdin . isTTY ) ) {
329- process . stderr . write (
330- "Error: Interactive mode requires a terminal. Use --yes for non-interactive mode.\n"
330+ throw new WizardError (
331+ "Interactive mode requires a terminal. Use --yes for non-interactive mode." ,
332+ { rendered : false }
331333 ) ;
332- process . exitCode = 1 ;
333- return false ;
334334 }
335335
336336 process . stderr . write ( `\n${ formatBanner ( ) } \n\n` ) ;
@@ -450,14 +450,12 @@ async function resolvePreSpinnerOptions(
450450 }
451451 log . error ( errorMessage ( err ) ) ;
452452 cancel ( "Setup failed." ) ;
453- process . exitCode = 1 ;
454- return null ;
453+ throw new WizardError ( errorMessage ( err ) ) ;
455454 }
456455 if ( typeof orgResult !== "string" ) {
457456 log . error ( orgResult . error ?? "Failed to resolve organization." ) ;
458457 cancel ( "Setup failed." ) ;
459- process . exitCode = 1 ;
460- return null ;
458+ throw new WizardError ( orgResult . error ?? "Failed to resolve organization." ) ;
461459 }
462460 opts = { ...opts , org : orgResult } ;
463461 }
@@ -524,8 +522,7 @@ async function resolvePreSpinnerOptions(
524522 `Create one at ${ terminalLink ( teamsUrl ) } and run sentry init again.`
525523 ) ;
526524 cancel ( "Setup failed." ) ;
527- process . exitCode = 1 ;
528- return null ;
525+ throw new WizardError ( "No teams in your organization." ) ;
529526 }
530527 } else if ( teams . length === 1 ) {
531528 opts = { ...opts , team : ( teams [ 0 ] as SentryTeam ) . slug } ;
@@ -641,8 +638,7 @@ export async function runWizard(initialOptions: WizardOptions): Promise<void> {
641638 spinState . running = false ;
642639 log . error ( errorMessage ( err ) ) ;
643640 cancel ( "Setup failed" ) ;
644- process . exitCode = 1 ;
645- return ;
641+ throw new WizardError ( errorMessage ( err ) ) ;
646642 }
647643
648644 const stepPhases = new Map < string , number > ( ) ;
@@ -659,8 +655,7 @@ export async function runWizard(initialOptions: WizardOptions): Promise<void> {
659655 spinState . running = false ;
660656 log . error ( `No suspend payload found for step "${ stepId } "` ) ;
661657 cancel ( "Setup failed" ) ;
662- process . exitCode = 1 ;
663- return ;
658+ throw new WizardError ( `No suspend payload found for step "${ stepId } "` ) ;
664659 }
665660
666661 const resumeData = await handleSuspendedStep (
@@ -701,8 +696,7 @@ export async function runWizard(initialOptions: WizardOptions): Promise<void> {
701696 }
702697 log . error ( errorMessage ( err ) ) ;
703698 cancel ( "Setup failed" ) ;
704- process . exitCode = 1 ;
705- return ;
699+ throw new WizardError ( errorMessage ( err ) ) ;
706700 }
707701
708702 handleFinalResult ( result , spin , spinState ) ;
@@ -721,7 +715,7 @@ function handleFinalResult(
721715 spinState . running = false ;
722716 }
723717 formatError ( result ) ;
724- process . exitCode = 1 ;
718+ throw new WizardError ( "Workflow returned an error" ) ;
725719 } else {
726720 if ( spinState . running ) {
727721 spin . stop ( "Done" ) ;
0 commit comments