Skip to content

Commit f39a1e3

Browse files
committed
fix(scan): add optional chaining for spinner safety
Handle cases where getSpinner() may return undefined by using optional chaining (?.) for all spinner method calls in scan command handlers. Changes: - handle-create-new-scan.mts: Add ?. for start(), successAndStop(), stop() - handle-scan-reach.mts: Add ?. for spinner methods - output-create-new-scan.mts: Add ?. for spinner methods - perform-reachability-analysis.mts: Add ?. for spinner methods This ensures scan commands work correctly even when spinner is unavailable.
1 parent 493e9a9 commit f39a1e3

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

packages/cli/src/commands/scan/handle-create-new-scan.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function handleCreateNewScan({
103103
logger.info('Auto-generation finished. Proceeding with Scan creation.')
104104
}
105105

106-
const spinner = getSpinner()!
106+
const spinner = getSpinner()
107107
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
108108
if (!supportedFilesCResult.ok) {
109109
debug('Failed to fetch supported scan file names')
@@ -116,14 +116,14 @@ export async function handleCreateNewScan({
116116
}
117117
debug(`Fetched ${supportedFilesCResult.data['size']} supported file types`)
118118

119-
spinner.start('Searching for local files to include in scan...')
119+
spinner?.start('Searching for local files to include in scan...')
120120

121121
const supportedFiles = supportedFilesCResult.data
122122
const packagePaths = await getPackageFilesForScan(targets, supportedFiles, {
123123
cwd,
124124
})
125125

126-
spinner.successAndStop('Finished searching for local files.')
126+
spinner?.successAndStop('Finished searching for local files.')
127127

128128
const wasValidInput = checkCommandInput(outputKind, {
129129
nook: true,
@@ -155,7 +155,7 @@ export async function handleCreateNewScan({
155155
debug('Reachability analysis enabled')
156156
debugDir({ reachabilityOptions: reach })
157157

158-
spinner.start()
158+
spinner?.start()
159159

160160
const reachResult = await performReachabilityAnalysis({
161161
branchName,
@@ -167,7 +167,7 @@ export async function handleCreateNewScan({
167167
spinner,
168168
})
169169

170-
spinner.stop()
170+
spinner?.stop()
171171

172172
if (!reachResult.ok) {
173173
await outputCreateNewScan(reachResult, { interactive, outputKind })

packages/cli/src/commands/scan/handle-scan-reach.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function handleScanReach({
3030
reachabilityOptions,
3131
targets,
3232
}: HandleScanReachConfig) {
33-
const spinner = getSpinner()!
33+
const spinner = getSpinner()
3434

3535
// Get supported file names
3636
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
@@ -43,7 +43,7 @@ export async function handleScanReach({
4343
return
4444
}
4545

46-
spinner.start(
46+
spinner?.start(
4747
'Searching for local manifest files to include in reachability analysis...',
4848
)
4949

@@ -52,7 +52,7 @@ export async function handleScanReach({
5252
cwd,
5353
})
5454

55-
spinner.successAndStop(
55+
spinner?.successAndStop(
5656
`Found ${packagePaths.length} ${pluralize('manifest file', { count: packagePaths.length })} for reachability analysis.`,
5757
)
5858

@@ -71,7 +71,7 @@ export async function handleScanReach({
7171
`Found ${packagePaths.length} local ${pluralize('file', { count: packagePaths.length })}`,
7272
)
7373

74-
spinner.start('Running reachability analysis...')
74+
spinner?.start('Running reachability analysis...')
7575

7676
const result = await performReachabilityAnalysis({
7777
cwd,

packages/cli/src/commands/scan/output-create-new-scan.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function outputCreateNewScan(
2525
const {
2626
interactive = false,
2727
outputKind = 'text',
28-
spinner = getSpinner()!,
28+
spinner = getSpinner(),
2929
} = { __proto__: null, ...options } as CreateNewScanOptions
3030

3131
if (!result.ok) {
@@ -39,15 +39,15 @@ export async function outputCreateNewScan(
3939
if (outputKind === 'json') {
4040
logger.log(serializeResultJson(result))
4141
if (wasSpinning) {
42-
spinner.start()
42+
spinner?.start()
4343
}
4444
return
4545
}
4646

4747
if (!result.ok) {
4848
logger.fail(failMsgWithBadge(result.message, result.cause))
4949
if (wasSpinning) {
50-
spinner.start()
50+
spinner?.start()
5151
}
5252
return
5353
}
@@ -72,7 +72,7 @@ export async function outputCreateNewScan(
7272
}
7373
logger.log('')
7474
if (wasSpinning) {
75-
spinner.start()
75+
spinner?.start()
7676
}
7777
return
7878
}
@@ -98,6 +98,6 @@ export async function outputCreateNewScan(
9898
}
9999

100100
if (wasSpinning) {
101-
spinner.start()
101+
spinner?.start()
102102
}
103103
}

packages/cli/src/commands/scan/perform-reachability-analysis.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ export async function performReachabilityAnalysis(
112112

113113
if (!uploadCResult.ok) {
114114
if (wasSpinning) {
115-
spinner.start()
115+
spinner?.start()
116116
}
117117
return uploadCResult
118118
}
119119

120120
tarHash = (uploadCResult.data as { tarHash?: string })?.tarHash
121121
if (!tarHash) {
122122
if (wasSpinning) {
123-
spinner.start()
123+
spinner?.start()
124124
}
125125
return {
126126
ok: false,
@@ -188,7 +188,7 @@ export async function performReachabilityAnalysis(
188188
})
189189

190190
if (wasSpinning) {
191-
spinner.start()
191+
spinner?.start()
192192
}
193193

194194
return coanaResult.ok

0 commit comments

Comments
 (0)