Skip to content

Commit a3b1f70

Browse files
committed
refactor(manifest): match the --pom path's spawn + error handling
Align the JVM facts path with convertGradleToMaven (the `--pom` generator), which is the direct-spawn sibling of these commands rather than the coana dlx wrapper: - spinner + captured output by default, stream on --verbose (unchanged intent). - On failure use process.exitCode = 1 + logger.fail(...) + return instead of throwing, so the facts path behaves identically to the pom path — including under --auto-manifest, where both now set exit 1 and continue the sequence. - runNeverThrow classifies a non-zero build exit by a numeric `code` (the utils/dlx.mts convention), not the registry's isSpawnError, which is broken upstream and never matches.
1 parent ac95036 commit a3b1f70

2 files changed

Lines changed: 45 additions & 19 deletions

File tree

src/commands/manifest/run-manifest-facts.mts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { renderResolutionErrorReport } from './scripts/resolution-report-render.
77
import { runManifestScript } from './scripts/run.mts'
88
import { accumulateSidecar } from './scripts/sidecar.mts'
99
import constants from '../../constants.mts'
10-
import { InputError } from '../../utils/errors.mts'
1110

1211
import type { BuildTool } from './scripts/build-tool.mts'
1312
import type { ManifestRunResult } from './scripts/run.mts'
@@ -72,17 +71,38 @@ export async function runManifestFacts({
7271
}
7372
const { spinner } = constants
7473
let result: ManifestRunResult
75-
if (verbose) {
76-
result = await runManifestScript(ecosystem, scriptOpts)
77-
} else {
78-
spinner.start(
79-
`Resolving ${ecosystem} dependencies (pass --verbose to stream build output) ...`,
80-
)
81-
try {
74+
try {
75+
if (verbose) {
76+
logger.info(
77+
`(Running ${ecosystem} with output streaming; this can take a while.)`,
78+
)
79+
result = await runManifestScript(ecosystem, scriptOpts)
80+
} else {
81+
logger.info(
82+
`(No live output; pass --verbose to stream the ${ecosystem} build output.)`,
83+
)
84+
spinner.start(`Resolving ${ecosystem} dependencies ...`)
8285
result = await runManifestScript(ecosystem, scriptOpts)
83-
} finally {
84-
spinner.stop()
86+
if (result.code === 0) {
87+
spinner.successAndStop(`Resolved ${ecosystem} dependencies.`)
88+
} else {
89+
spinner.failAndStop(
90+
`${ecosystem} build exited with code ${result.code}.`,
91+
)
92+
}
8593
}
94+
} catch (e) {
95+
// Only a spawn-level failure (e.g. the build tool missing from PATH) reaches
96+
// here; runNeverThrow returns non-zero build exits rather than throwing.
97+
if (!verbose) {
98+
spinner.failAndStop(`Failed to run ${ecosystem}.`)
99+
}
100+
process.exitCode = 1
101+
logger.fail(
102+
`Could not run the ${ecosystem} build tool` +
103+
(verbose ? `: ${e}` : ' (run with --verbose for details).'),
104+
)
105+
return
86106
}
87107
const { artifactPaths, code, facts, report, stderr, stdout } = result
88108

@@ -97,10 +117,12 @@ export async function runManifestFacts({
97117
if (ignoreUnresolved) {
98118
logger.warn(rendered.summary)
99119
} else {
120+
process.exitCode = 1
121+
logger.fail(rendered.summary)
100122
if (verbose && rendered.details) {
101123
logger.log(rendered.details)
102124
}
103-
throw new InputError(rendered.summary)
125+
return
104126
}
105127
}
106128
if (rendered.nonBlockingNotice) {
@@ -131,10 +153,12 @@ export async function runManifestFacts({
131153
}
132154
}
133155
const message = `The ${ecosystem} build failed (exit code ${code}) before producing any Socket facts.`
134-
if (!ignoreUnresolved) {
135-
throw new InputError(message)
156+
if (ignoreUnresolved) {
157+
logger.warn(message)
158+
return
136159
}
137-
logger.warn(message)
160+
process.exitCode = 1
161+
logger.fail(message)
138162
return
139163
}
140164

src/commands/manifest/scripts/run.mts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ async function runNeverThrow(
7070
stderr: typeof result.stderr === 'string' ? result.stderr : '',
7171
}
7272
} catch (e) {
73-
// A non-zero exit rejects with the spawn-result shape: a numeric `code` plus
74-
// captured stdout/stderr. Return it so the caller can assemble failure
75-
// records. Anything else (e.g. a missing executable, whose `code` is the
76-
// string 'ENOENT') propagates. Duck-typed on purpose: the registry's
77-
// isSpawnError is unreliable, so the numeric-code check is the real signal.
73+
// A build tool that exits non-zero rejects with the spawn-result shape: a
74+
// numeric exit `code` plus captured stdout/stderr. Return it so the caller
75+
// can assemble failure records / surface the output. Anything else — e.g. a
76+
// missing executable, whose `code` is a string like 'ENOENT' — propagates.
77+
// This mirrors how utils/dlx.mts classifies spawn failures (a numeric `code`
78+
// is a real process exit); the registry's isSpawnError is avoided here
79+
// because it is currently broken and never matches.
7880
if (
7981
e !== null &&
8082
typeof e === 'object' &&

0 commit comments

Comments
 (0)