Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/commands/fix/coana-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../../utils/coana.mts'
import { findSocketYmlSync } from '../../utils/config.mts'
import { debugDir, debugFn } from '../../utils/debug.mts'
import { getErrorCause } from '../../utils/errors.mts'
import { errorMessage } from '../../utils/errors.mts'
import { readJsonSync, withTmpDir } from '../../utils/fs.mts'
import {
gitCheckoutBranch,
Expand Down Expand Up @@ -763,9 +763,7 @@ async function coanaFixWithFacts(
}
} else if (!fixCResult.ok) {
if (!silence) {
logger.error(
`Update failed for ${ghsaId}: ${getErrorCause(fixCResult)}`,
)
logger.error(`Update failed for ${ghsaId}: ${errorMessage(fixCResult)}`)
}
// Clean up temp file on failure.
try {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/logout/attempt-logout.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { applyLogout } from './apply-logout.mts'
import constants from '../../constants.mts'
import { isConfigFromFlag } from '../../utils/config.mts'
import { getErrorCause } from '../../utils/errors.mts'
import { errorMessage } from '../../utils/errors.mts'
import { logger } from '../../utils/logger.mts'
import { logoutOAuth } from '../../utils/oauth.mts'
import { getDefaultProxyUrl } from '../../utils/sdk.mts'
Expand Down Expand Up @@ -37,6 +37,6 @@ export async function attemptLogout() {
}
} catch (error) {
logger.fail('Failed to complete logout steps')
logger.warn(getErrorCause(error))
logger.warn(errorMessage(error))
}
}
2 changes: 1 addition & 1 deletion src/commands/logout/attempt-logout.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vi.mock('../../utils/config.mts', () => ({
isConfigFromFlag: mockIsConfigFromFlag,
}))
vi.mock('../../utils/errors.mts', () => ({
getErrorCause: (error: unknown) =>
errorMessage: (error: unknown) =>
error instanceof Error ? error.message : 'Unknown error',
}))
vi.mock('../../utils/oauth.mts', () => ({ logoutOAuth: mockLogoutOAuth }))
Expand Down
10 changes: 5 additions & 5 deletions src/commands/manifest/bazel/cleanup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
getBazelEnvironmentValue,
spawnBazel,
} from './process.mts'
import { getErrorCause, isErrnoException } from '../../../utils/errors.mts'
import { errorMessage, isErrnoException } from '../../../utils/errors.mts'
import { logger } from '../../../utils/logger.mts'

import type { BazelQueryOptions } from './query-runner.mts'
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function removeBazelTempdir(dir: string): Promise<boolean> {
return true
} catch (error) {
logger.warn(
`Bazel temporary directory could not be removed: ${dir}. ${getErrorCause(error)}`,
`Bazel temporary directory could not be removed: ${dir}. ${errorMessage(error)}`,
)
return false
}
Expand Down Expand Up @@ -105,7 +105,7 @@ export async function cleanUpBazelOutputRoot(
listed = findServerPids(root)
} catch (e) {
logger.warn(
`Bazel output root kept because its servers could not be checked: ${root}. ${getErrorCause(e)}`,
`Bazel output root kept because its servers could not be checked: ${root}. ${errorMessage(e)}`,
)
}
const servers = new Set(listed)
Expand Down Expand Up @@ -168,7 +168,7 @@ export async function shutDownBazelServer(
pid = readServerPid(outputBase)
await spawnBazel(opts.bin, [...startupFlags, 'shutdown'], spawnOptions)
} catch (error) {
logger.warn(`Bazel shutdown failed in ${opts.cwd}. ${getErrorCause(error)}`)
logger.warn(`Bazel shutdown failed in ${opts.cwd}. ${errorMessage(error)}`)
}
return pid
}
Expand Down Expand Up @@ -240,7 +240,7 @@ async function stopBazelServer(pid: number): Promise<boolean> {
} catch (e) {
if (!isErrnoException(e) || e.code !== 'ESRCH') {
logger.warn(
`Bazel server ${pid} could not be stopped. ${getErrorCause(e)}`,
`Bazel server ${pid} could not be stopped. ${errorMessage(e)}`,
)
return false
}
Expand Down
12 changes: 6 additions & 6 deletions src/commands/manifest/bazel/extract_bazel_to_maven.mts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
getBazelInvocationFlags,
} from './workspace-detect.mts'
import { findWorkspaceRoots } from './workspace-walk.mts'
import { getErrorCause } from '../../../utils/errors.mts'
import { errorMessage } from '../../../utils/errors.mts'
import { IGNORED_DIRS } from '../../../utils/glob.mts'
import { logger } from '../../../utils/logger.mts'

Expand Down Expand Up @@ -430,7 +430,7 @@ async function writeCompletenessSummary(args: {
} catch (e) {
if (verbose) {
logger.log(
`[VERBOSE] completeness summary not written (${getErrorCause(e)}); the run result still carries the signal`,
`[VERBOSE] completeness summary not written (${errorMessage(e)}); the run result still carries the signal`,
)
}
}
Expand Down Expand Up @@ -676,7 +676,7 @@ export async function extractBazelToMaven(
if (pythonShimDir) {
await removeBazelTempdir(pythonShimDir)
}
logger.fail(`Unexpected error in bazel2maven: ${getErrorCause(e)}`)
logger.fail(`Unexpected error in bazel2maven: ${errorMessage(e)}`)
if (verbose) {
logger.group('[VERBOSE] error:')
logger.log(e)
Expand Down Expand Up @@ -772,7 +772,7 @@ export async function extractBazelToMaven(
// here": record it so the run is flagged not-complete (a hard failure
// when nothing else was analyzable, partial otherwise) rather than
// silently skipped.
const reason = getErrorCause(e)
const reason = errorMessage(e)
if (verbose) {
logger.log(
`[VERBOSE] workspace ${workspaceRoot}: load failed (${reason})`,
Expand Down Expand Up @@ -959,7 +959,7 @@ export async function extractBazelToMaven(
// Best-effort per hub: a write failure must not abort the walk and
// discard the manifests other hubs already produced.
logger.warn(
`@${repoName}: failed to write manifest (${getErrorCause(e)}); skipping this hub`,
`@${repoName}: failed to write manifest (${errorMessage(e)}); skipping this hub`,
)
hubsFailed += 1
hubOutcomes.push({
Expand Down Expand Up @@ -1162,7 +1162,7 @@ export async function extractBazelToMaven(
workspaceOutcomes,
}
} catch (e) {
logger.fail(`Unexpected error in bazel2maven: ${getErrorCause(e)}`)
logger.fail(`Unexpected error in bazel2maven: ${errorMessage(e)}`)
if (verbose) {
logger.group('[VERBOSE] error:')
logger.log(e)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/manifest/bazel/extract_bazel_to_pypi.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
detectWorkspaceMode,
getBazelInvocationFlags,
} from './workspace-detect.mts'
import { InputError, getErrorCause } from '../../../utils/errors.mts'
import { InputError, errorMessage } from '../../../utils/errors.mts'
import { logger } from '../../../utils/logger.mts'

import type { PypiHubCandidate } from './pypi-discovery.mts'
Expand Down Expand Up @@ -298,7 +298,7 @@ export async function extractBazelToPypi(
ok: true,
}
} catch (e) {
logger.fail(`Unexpected error in bazel2pypi: ${getErrorCause(e)}`)
logger.fail(`Unexpected error in bazel2pypi: ${errorMessage(e)}`)
if (verbose) {
logger.group('[VERBOSE] error:')
logger.log(e)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/manifest/bazel/output-base-check.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'node:fs'
import path from 'node:path'

import { InputError, getErrorCause } from '../../../utils/errors.mts'
import { InputError, errorMessage } from '../../../utils/errors.mts'

// Validates that --bazel-output-base is a path we can use as Bazel's output_base.
// Throws InputError if:
Expand Down Expand Up @@ -40,7 +40,7 @@ export function validateOutputBase(outputBase: string, cwd: string): void {
mkdirSync(resolved, { recursive: true })
} catch (e) {
throw new InputError(
`--bazel-output-base could not be created at ${resolved}: ${getErrorCause(e)}`,
`--bazel-output-base could not be created at ${resolved}: ${errorMessage(e)}`,
)
}
}
4 changes: 2 additions & 2 deletions src/commands/manifest/bazel/pypi-discovery.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
import path from 'node:path'

import { getErrorCause } from '../../../utils/errors.mts'
import { errorMessage } from '../../../utils/errors.mts'
import { logger } from '../../../utils/logger.mts'

import type { RepoProbe } from './repo-discovery.mts'
Expand Down Expand Up @@ -449,7 +449,7 @@ export async function validatePypiHub(
if (verbose) {
logger.log(
`[VERBOSE] discovery: probe @${hubName}: REJECT (probe threw):`,
getErrorCause(e),
errorMessage(e),
)
}
return { valid: false, stdout: '' }
Expand Down
4 changes: 2 additions & 2 deletions src/commands/manifest/convert_sbt_to_maven.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path'
import constants from '../../constants.mts'
import { resolveBuildToolBin } from './scripts/build-tool.mts'
import { isStandaloneSea } from '../../sea/runtime.mts'
import { getErrorCause } from '../../utils/errors.mts'
import { errorMessage } from '../../utils/errors.mts'
import { safeReadFile } from '../../utils/fs.mts'
import { logger } from '../../utils/logger.mts'
import { spawn } from '../../utils/spawn.mts'
Expand Down Expand Up @@ -154,7 +154,7 @@ export async function convertSbtToMaven({
copied.push(destPath)
} catch (e) {
logger.warn(
`Failed to copy \`${pomPath}\` to \`${destPath}\`: ${getErrorCause(e)}`,
`Failed to copy \`${pomPath}\` to \`${destPath}\`: ${errorMessage(e)}`,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/wrapper/postinstall-wrapper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { checkSocketWrapperSetup } from './check-socket-wrapper-setup.mts'
import constants from '../../constants.mts'
import { getBashrcDetails } from '../../utils/completion.mts'
import { debugDir, debugFn } from '../../utils/debug.mts'
import { getErrorCause } from '../../utils/errors.mts'
import { errorMessage } from '../../utils/errors.mts'
import { logger } from '../../utils/logger.mts'
import { confirm } from '../../utils/prompts.mts'
import { updateInstalledTabCompletionScript } from '../install/setup-tab-completion.mts'
Expand Down Expand Up @@ -82,7 +82,7 @@ async function setupShadowNpm(query: string): Promise<void> {
}
} catch (e) {
throw new Error(
`There was an issue setting up the alias: ${getErrorCause(e)}`,
`There was an issue setting up the alias: ${errorMessage(e)}`,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sea/build-sea.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { stageSynp } from './stage/synp.mts'
import { stageUv } from './stage/uv.mts'
import { SEA_VERSION } from './version.mts'
import { digestVfs } from './vfs-digest.mts'
import { getErrorCause } from '../utils/errors.mts'
import { errorMessage } from '../utils/errors.mts'
import { quotePowerShell } from '../utils/quote-powershell.mts'

const SEA_DIRECTORY = path.dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -985,7 +985,7 @@ async function main(): Promise<void> {
}
return [
new Error(
`SEA preparation failed: ${prepLabels[index]}: ${getErrorCause(result.reason)}`,
`SEA preparation failed: ${prepLabels[index]}: ${errorMessage(result.reason)}`,
{ cause: result.reason },
),
]
Expand Down
6 changes: 2 additions & 4 deletions src/sea/download-bytes.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable no-await-in-loop -- Retry attempts must run sequentially. */
import { errorMessage } from '../utils/errors.mts'

const MAX_ATTEMPTS = 3
const RETRY_DELAYS = [500, 1_000] as const
const RETRYABLE_HTTP_STATUSES = new Set([408, 429, 500, 502, 503, 504])
Expand All @@ -22,10 +24,6 @@ type DownloadBytesOptions = {
acceptedStatuses?: readonly number[] | undefined
}

export function errorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}

export function isRetryable(error: unknown): boolean {
const seen = new Set<unknown>()
let current: unknown = error
Expand Down
5 changes: 3 additions & 2 deletions src/sea/stage/coana.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getDefaultOrgSlug } from '../../commands/ci/fetch-default-org-slug.mts'
import { COANA_CLI_VERSION } from '../../constants.mts'
import { apiFetch, sendApiRequest } from '../../utils/api.mts'
import { envAsBoolean } from '../../utils/env.mts'
import { errorMessage } from '../../utils/errors.mts'
import { SEA_COANA_VFS_PATHS, seaCoanaPaths } from '../paths/coana.mts'

const COMPONENTS = ['analyzers', 'cli'] as const
Expand Down Expand Up @@ -91,7 +92,7 @@ async function fetchArtifacts(org: string): Promise<CoanaArtifacts> {
)
if (!result.ok) {
throw new Error(
`the Socket API denied Coana artifact access: ${result.message}${result.cause ? ` (${result.cause})` : ''}`,
result.cause ? `${result.message} (${result.cause})` : result.message,
)
}
return parseArtifacts(result.data)
Expand Down Expand Up @@ -228,7 +229,7 @@ export async function stageCoana(
artifacts = await fetchArtifacts(org.data)
} catch (error) {
throw new Error(
`Coana ${COANA_CLI_VERSION} download failed for ${org.data}. Where: Socket API artifact access. Saw: ${error instanceof Error ? error.message : String(error)}; wanted: the pinned CLI and analyzer artifacts. Fix: ensure SOCKET_API_TOKEN_FOR_CLI_AND_SFW can access Coana reachability artifacts for this organization, then retry the 2.x RC build.`,
`Could not fetch Coana ${COANA_CLI_VERSION} artifacts for ${org.data}: ${errorMessage(error)}. Check that the build token can access Coana artifacts for this organization.`,
{ cause: error },
)
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
debugDir,
debugFn,
} from './debug.mts'
import { getErrorCause, isErrnoException } from './errors.mts'
import { errorMessage, isErrnoException } from './errors.mts'
import { logger } from './logger.mts'
import { getRequirements, getRequirementsKey } from './requirements.mts'
import {
Expand Down Expand Up @@ -658,7 +658,7 @@ export async function queryApiSafeTextWithStatus(
return {
ok: false,
message: 'Authentication Error',
cause: getErrorCause(error),
cause: errorMessage(error),
}
}
if (!apiToken) {
Expand Down Expand Up @@ -751,7 +751,7 @@ export async function queryApiSafeTextWithStatus(

const cause =
isErrnoException(e) && e.code === 'ETIMEDOUT'
? `${getErrorCause(e)} (path: ${path})`
? `${errorMessage(e)} (path: ${path})`
: `Unexpected error reading response text (path: ${path})`

return {
Expand Down Expand Up @@ -827,7 +827,7 @@ export async function sendApiRequest<T>(
return {
ok: false,
message: 'Authentication Error',
cause: getErrorCause(error),
cause: errorMessage(error),
}
}
if (!apiToken) {
Expand Down Expand Up @@ -922,7 +922,7 @@ export async function sendApiRequest<T>(
debugDir('error', e)
const cause =
isErrnoException(e) && e.code === 'ETIMEDOUT'
? `${getErrorCause(e)} (path: ${path})`
? `${errorMessage(e)} (path: ${path})`
: `Unexpected error parsing response JSON (path: ${path})`
return {
ok: false,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ vi.mock('./config.mts', () => ({
isConfigFromFlag: mockIsConfigFromFlag,
}))
vi.mock('./errors.mts', () => ({
getErrorCause: (error: unknown) =>
errorMessage: (error: unknown) =>
error instanceof Error ? error.message : 'Unknown error',
}))

Expand Down
8 changes: 4 additions & 4 deletions src/utils/coana/release.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import constants, {
SOCKET_CLI_API_TOKEN_VARIABLES,
} from '../../constants.mts'
import { apiFetch, sendApiRequest } from '../api.mts'
import { getErrorCause } from '../errors.mts'
import { errorMessage } from '../errors.mts'
import { withTmpDir } from '../fs.mts'
import {
getCliUserAgent,
Expand Down Expand Up @@ -149,7 +149,7 @@ function coanaSpawnErrorResult(e: unknown): CResult<string> {
}
const detailSuffix = details.length ? ` (${details.join(', ')})` : ''
// Coana logs some failures, e.g. unresolved Gradle dependencies, to stdout.
const detail = stderr || stdout || getErrorCause(e)
const detail = stderr || stdout || errorMessage(e)
const message =
typeof exitCode === 'string'
? `Failed to launch Coana${detailSuffix}: ${detail}`
Expand Down Expand Up @@ -276,7 +276,7 @@ async function getCoanaCliDir(
return {
ok: false,
message: `Failed to get the Coana CLI ${versionSpec}`,
cause: getErrorCause(e),
cause: errorMessage(e),
}
}

Expand Down Expand Up @@ -598,7 +598,7 @@ export async function spawnCoana(
return {
ok: false,
message: 'Could not prepare the embedded Coana CLI',
cause: getErrorCause(error),
cause: errorMessage(error),
}
}
}
Expand Down
Loading
Loading