Skip to content

Commit 7f4839d

Browse files
committed
improve Coana error logging and add e2e test retries
- Include exit code and signal in Coana failure messages - Log Coana version, target, and cwd on reachability analysis failure - Add retry: 2 to all scan reach e2e tests for transient CI failures
1 parent c2e1f3b commit 7f4839d

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

src/commands/scan/cmd-scan-reach.e2e.test.mts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ describe('socket scan reach (E2E tests)', async () => {
394394
await tempFixture.cleanup()
395395
}
396396
},
397-
{ timeout: longTestTimeout },
397+
{ retry: 2, timeout: longTestTimeout },
398398
)
399399

400400
cmdit(
@@ -491,7 +491,7 @@ describe('socket scan reach (E2E tests)', async () => {
491491
await tempFixture.cleanup()
492492
}
493493
},
494-
{ timeout: testTimeout },
494+
{ retry: 2, timeout: testTimeout },
495495
)
496496
})
497497

@@ -603,7 +603,7 @@ describe('socket scan reach (E2E tests)', async () => {
603603
await tempFixture.cleanup()
604604
}
605605
},
606-
{ timeout: testTimeout },
606+
{ retry: 2, timeout: testTimeout },
607607
)
608608

609609
cmdit(
@@ -681,7 +681,7 @@ describe('socket scan reach (E2E tests)', async () => {
681681
await tempFixture.cleanup()
682682
}
683683
},
684-
{ timeout: testTimeout },
684+
{ retry: 2, timeout: testTimeout },
685685
)
686686

687687
cmdit(
@@ -779,7 +779,7 @@ describe('socket scan reach (E2E tests)', async () => {
779779
await tempFixture.cleanup()
780780
}
781781
},
782-
{ timeout: testTimeout },
782+
{ retry: 2, timeout: testTimeout },
783783
)
784784

785785
cmdit(
@@ -836,7 +836,7 @@ describe('socket scan reach (E2E tests)', async () => {
836836
await tempFixture.cleanup()
837837
}
838838
},
839-
{ timeout: testTimeout },
839+
{ retry: 2, timeout: testTimeout },
840840
)
841841

842842
cmdit(
@@ -923,7 +923,7 @@ describe('socket scan reach (E2E tests)', async () => {
923923
await tempFixture.cleanup()
924924
}
925925
},
926-
{ timeout: testTimeout },
926+
{ retry: 2, timeout: testTimeout },
927927
)
928928
})
929929

@@ -1027,7 +1027,7 @@ describe('socket scan reach (E2E tests)', async () => {
10271027
await tempFixture.cleanup()
10281028
}
10291029
},
1030-
{ timeout: testTimeout },
1030+
{ retry: 2, timeout: testTimeout },
10311031
)
10321032

10331033
cmdit(
@@ -1127,7 +1127,7 @@ describe('socket scan reach (E2E tests)', async () => {
11271127
await tempFixture.cleanup()
11281128
}
11291129
},
1130-
{ timeout: testTimeout },
1130+
{ retry: 2, timeout: testTimeout },
11311131
)
11321132
})
11331133
})

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import path from 'node:path'
22

3+
import { logger } from '@socketsecurity/registry/lib/logger'
4+
35
import constants from '../../constants.mts'
46
import { handleApiCall } from '../../utils/api.mts'
57
import { extractTier1ReachabilityScanId } from '../../utils/coana.mts'
@@ -227,15 +229,25 @@ export async function performReachabilityAnalysis(
227229
spinner.start()
228230
}
229231

230-
return coanaResult.ok
231-
? {
232-
ok: true,
233-
data: {
234-
// Use the actual output filename for the scan.
235-
reachabilityReport: outputFilePath,
236-
tier1ReachabilityScanId:
237-
extractTier1ReachabilityScanId(outputFilePath),
238-
},
239-
}
240-
: coanaResult
232+
if (!coanaResult.ok) {
233+
const coanaVersion =
234+
reachabilityOptions.reachVersion ||
235+
constants.ENV.INLINED_SOCKET_CLI_COANA_TECH_CLI_VERSION
236+
logger.error(
237+
`Coana reachability analysis failed. Version: ${coanaVersion}, target: ${analysisTarget}, cwd: ${cwd}`,
238+
)
239+
if (coanaResult.message) {
240+
logger.error(`Details: ${coanaResult.message}`)
241+
}
242+
return coanaResult
243+
}
244+
245+
return {
246+
ok: true,
247+
data: {
248+
// Use the actual output filename for the scan.
249+
reachabilityReport: outputFilePath,
250+
tier1ReachabilityScanId: extractTier1ReachabilityScanId(outputFilePath),
251+
},
252+
}
241253
}

src/utils/dlx.mts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,21 @@ export async function spawnCoanaDlx(
278278
return { ok: true, data: output.stdout }
279279
} catch (e) {
280280
const stderr = (e as any)?.stderr
281+
const exitCode = (e as any)?.code
282+
const signal = (e as any)?.signal
281283
const cause = getErrorCause(e)
282-
const message = stderr || cause
284+
// Build a descriptive error message with exit code and signal details.
285+
const details: string[] = []
286+
if (typeof exitCode === 'number') {
287+
details.push(`exit code ${exitCode}`)
288+
}
289+
if (signal) {
290+
details.push(`signal ${signal}`)
291+
}
292+
const detailSuffix = details.length ? ` (${details.join(', ')})` : ''
293+
const message = stderr
294+
? `Coana command failed${detailSuffix}: ${stderr}`
295+
: `Coana command failed${detailSuffix}: ${cause}`
283296
return {
284297
ok: false,
285298
data: e,

0 commit comments

Comments
 (0)