Skip to content

Commit a4a5c8a

Browse files
committed
fix(cli): align env/ + constants/ + build-script error messages with 4-ingredient strategy
Rewrites runtime and build-time error messages for the build-inlined version/checksum pipeline to follow the What / Where / Saw vs. wanted / Fix strategy from CLAUDE.md. Sources (runtime): - env/coana-version.mts, env/sfw-version.mts (2 getters), env/socket-basics-version.mts, env/socket-patch-version.mts, env/trufflehog-version.mts, env/trivy-version.mts, env/opengrep-version.mts, env/pycli-version.mts — 9 "INLINED_X not found" errors. Each now names the exact env var, the bundle-tools.json path it comes from, and how to rebuild (`pnpm run build:cli`). - env/checksum-utils.mts — parseChecksums() and requireChecksum() now show the exact JSON.parse error or the list of known assets so you can see what was in vs. out of the map. - constants/paths.mts — getSocketRegistryPath() now enumerates every env var the app-data lookup checks (HOME, USERPROFILE, LOCALAPPDATA, XDG_DATA_HOME) so a cold environment tells you which to set. Sources (build-time scripts, same message style for consistency): - scripts/sea-build-utils/downloads.mts — 3 checksum-missing errors in the SEA build path, each now names the bundle-tools.json key and tells you to run `pnpm run sync-checksums`. No tests pinned these messages (only dist/cli.js — unchecked-in build output). Follows strategy from #1254. Continues #1255, #1256, #1257.
1 parent fc5591f commit a4a5c8a

11 files changed

Lines changed: 18 additions & 20 deletions

packages/cli/scripts/sea-build-utils/downloads.mts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ export async function downloadExternalTools(platform, arch, isMusl = false) {
332332

333333
if (!sha256) {
334334
throw new Error(
335-
`Missing SHA-256 checksum for ${toolName} asset: ${assetName}. ` +
336-
'This is a security requirement. Please update bundle-tools.json with the correct checksum.',
335+
`bundle-tools.json tools.${toolName}.checksums has no entry for "${assetName}" (seen: ${Object.keys(toolConfig?.checksums ?? {}).join(', ') || '<empty>'}); run \`pnpm run sync-checksums\` to populate — builds must verify every external download`,
337336
)
338337
}
339338

@@ -473,8 +472,7 @@ export async function downloadExternalTools(platform, arch, isMusl = false) {
473472

474473
if (!wheelSha256) {
475474
throw new Error(
476-
`Missing SHA-256 checksum for socketsecurity wheel: ${wheelFilename}. ` +
477-
'Please update bundle-tools.json with the correct checksum.',
475+
`bundle-tools.json tools.socketsecurity.checksums has no entry for "${wheelFilename}" (seen: ${Object.keys(pyCliConfig.checksums ?? {}).join(', ') || '<empty>'}); run \`pnpm run sync-checksums\` to populate from PyPI — builds must verify the wheel hash`,
478476
)
479477
}
480478

@@ -544,8 +542,7 @@ export async function downloadExternalTools(platform, arch, isMusl = false) {
544542
const archiveSha256 = socketBasicsConfig.checksums?.[archiveKey]
545543
if (!archiveSha256) {
546544
throw new Error(
547-
`Missing SHA-256 checksum for socket-basics archive: ${archiveKey}. ` +
548-
'Please update bundle-tools.json with the correct checksum.',
545+
`bundle-tools.json tools["socket-basics"].checksums has no entry for "${archiveKey}" (seen: ${Object.keys(socketBasicsConfig.checksums ?? {}).join(', ') || '<empty>'}); run \`pnpm run sync-checksums\` to populate from the GitHub release — builds must verify the source tarball hash`,
549546
)
550547
}
551548

packages/cli/src/constants/paths.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ export function getSocketCachePath(): string {
190190
export function getSocketRegistryPath(): string {
191191
const appDataPath = getSocketAppDataPath()
192192
if (!appDataPath) {
193-
throw new Error('Unable to determine Socket app data path')
193+
throw new Error(
194+
`could not determine the Socket app-data directory: getSocketAppDataPath() returned undefined because none of HOME, USERPROFILE, LOCALAPPDATA, or XDG_DATA_HOME are set; export one of those env vars (typically HOME on macOS/Linux or LOCALAPPDATA on Windows) and retry`,
195+
)
194196
}
195197
return path.join(appDataPath, 'registry')
196198
}

packages/cli/src/env/checksum-utils.mts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export function parseChecksums(
2828
}
2929
try {
3030
return JSON.parse(jsonString) as Checksums
31-
} catch {
31+
} catch (e) {
3232
throw new Error(
33-
`Failed to parse ${toolName} checksums. This indicates a build configuration error.`,
33+
`INLINED_${toolName.toUpperCase()}_CHECKSUMS is not valid JSON at runtime (JSON.parse threw: ${(e as Error).message}); the build-time inline step produced corrupt data — rebuild socket-cli (\`pnpm run build:cli\`) and check bundle-tools.json tools.${toolName}.checksums`,
3434
)
3535
}
3636
}
@@ -62,8 +62,7 @@ export function requireChecksum(
6262
const sha256 = checksums[assetName]
6363
if (!sha256) {
6464
throw new Error(
65-
`Missing SHA-256 checksum for ${toolName} asset: ${assetName}. ` +
66-
'This is a security requirement. Please update bundle-tools.json with the correct checksum.',
65+
`bundle-tools.json tools.${toolName}.checksums has no entry for asset "${assetName}" (available: ${Object.keys(checksums).join(', ') || '<empty>'}); add the SHA-256 for this asset via \`pnpm run sync-checksums\` — do NOT ship without verification`,
6766
)
6867
}
6968
return sha256

packages/cli/src/env/coana-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getCoanaVersion(): string {
1212
const version = process.env['INLINED_COANA_VERSION']
1313
if (!version) {
1414
throw new Error(
15-
'INLINED_COANA_VERSION not found. Please ensure @coana-tech/cli is properly configured in bundle-tools.json.',
15+
`process.env.INLINED_COANA_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools["@coana-tech/cli"].version — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
1616
)
1717
}
1818
return version

packages/cli/src/env/opengrep-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getOpengrepVersion(): string {
1212
const version = process.env['INLINED_OPENGREP_VERSION']
1313
if (!version) {
1414
throw new Error(
15-
'INLINED_OPENGREP_VERSION not found. Please ensure opengrep is properly configured in bundle-tools.json.',
15+
`process.env.INLINED_OPENGREP_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools.opengrep.version — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
1616
)
1717
}
1818
return version

packages/cli/src/env/pycli-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function getPyCliVersion(): string {
1919
const version = process.env['INLINED_PYCLI_VERSION']
2020
if (!version) {
2121
throw new Error(
22-
'INLINED_PYCLI_VERSION not set - build configuration error. Please rebuild the CLI.',
22+
`process.env.INLINED_PYCLI_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools.socketsecurity.version (PyPI package) — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
2323
)
2424
}
2525
return version

packages/cli/src/env/sfw-version.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function getSwfVersion(): string {
1919
const version = process.env['INLINED_SFW_VERSION']
2020
if (!version) {
2121
throw new Error(
22-
'INLINED_SFW_VERSION not found. Please ensure sfw is properly configured in bundle-tools.json.',
22+
`process.env.INLINED_SFW_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools.sfw.version (GitHub release tag) — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
2323
)
2424
}
2525
return version
@@ -32,7 +32,7 @@ export function getSfwNpmVersion(): string {
3232
const version = process.env['INLINED_SFW_NPM_VERSION']
3333
if (!version) {
3434
throw new Error(
35-
'INLINED_SFW_NPM_VERSION not found. Please ensure sfw npm.version is configured in bundle-tools.json.',
35+
`process.env.INLINED_SFW_NPM_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools.sfw.npm.version (npm package semver) — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
3636
)
3737
}
3838
return version

packages/cli/src/env/socket-basics-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getSocketBasicsVersion(): string {
1212
const version = process.env['INLINED_SOCKET_BASICS_VERSION']
1313
if (!version) {
1414
throw new Error(
15-
'INLINED_SOCKET_BASICS_VERSION not found. Please ensure socket-basics is properly configured in bundle-tools.json.',
15+
`process.env.INLINED_SOCKET_BASICS_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools["socket-basics"].version — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
1616
)
1717
}
1818
return version

packages/cli/src/env/socket-patch-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getSocketPatchVersion(): string {
1212
const version = process.env['INLINED_SOCKET_PATCH_VERSION']
1313
if (!version) {
1414
throw new Error(
15-
'INLINED_SOCKET_PATCH_VERSION not found. Please ensure socket-patch is properly configured in bundle-tools.json.',
15+
`process.env.INLINED_SOCKET_PATCH_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools["socket-patch"].version — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
1616
)
1717
}
1818
return version

packages/cli/src/env/trivy-version.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getTrivyVersion(): string {
1212
const version = process.env['INLINED_TRIVY_VERSION']
1313
if (!version) {
1414
throw new Error(
15-
'INLINED_TRIVY_VERSION not found. Please ensure trivy is properly configured in bundle-tools.json.',
15+
`process.env.INLINED_TRIVY_VERSION is empty at runtime; this value should be inlined at build time from bundle-tools.json tools.trivy.version — rebuild socket-cli (\`pnpm run build:cli\`) or check that esbuild's define step ran`,
1616
)
1717
}
1818
return version

0 commit comments

Comments
 (0)