Skip to content

Commit b6c0ea4

Browse files
authored
fix: improve socket fix error messages for misplaced IDs and missing directories (#1199)
* fix: improve socket fix error messages for misplaced IDs and missing directories Detect when a GHSA/CVE/PURL identifier is passed as a positional argument instead of with --id and show a helpful suggestion. Also validate the target directory exists before making API calls. Bump version to 1.1.83. * chore: retrigger CI
1 parent c06f2f5 commit b6c0ea4

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [1.1.83](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.83) - 2026-04-14
8+
9+
### Fixed
10+
- `socket fix` now shows a clear error when a vulnerability ID (GHSA, CVE, or PURL) is passed as a positional argument instead of with `--id`, with a helpful "Did you mean" suggestion
11+
- `socket fix` now shows a clear error when the target directory does not exist, instead of a confusing API error about missing files
12+
713
## [1.1.82](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.82) - 2026-04-13
814

915
### Changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "1.1.82",
3+
"version": "1.1.83",
44
"description": "CLI for Socket.dev",
55
"homepage": "https://github.com/SocketDev/socket-cli",
66
"license": "MIT AND OFL-1.1",

src/commands/fix/cmd-fix.integration.test.mts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,7 @@ describe('socket fix', async () => {
442442
async cmd => {
443443
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
444444
const output = stdout + stderr
445-
expect(output).toMatch(
446-
/Unable to resolve|An error was thrown while requesting/,
447-
)
445+
expect(output).toMatch(/Target directory does not exist/)
448446
expect(code, 'should exit with non-zero code').not.toBe(0)
449447
},
450448
)
@@ -737,9 +735,7 @@ describe('socket fix', async () => {
737735
async cmd => {
738736
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
739737
const output = stdout + stderr
740-
expect(output).toMatch(
741-
/Unable to resolve|An error was thrown while requesting/,
742-
)
738+
expect(output).toMatch(/Target directory does not exist/)
743739
expect(code).toBeGreaterThan(0)
744740
},
745741
)

src/commands/fix/cmd-fix.mts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from 'node:fs'
12
import path from 'node:path'
23

34
import terminalLink from 'terminal-link'
@@ -400,6 +401,34 @@ async function run(
400401
return
401402
}
402403

404+
// Check if a positional argument looks like a vulnerability ID (GHSA, CVE,
405+
// or PURL) that was likely intended to be passed with --id.
406+
const rawInput = cli.input[0]
407+
if (
408+
rawInput &&
409+
(/^GHSA-/i.test(rawInput) ||
410+
/^CVE-/i.test(rawInput) ||
411+
rawInput.startsWith('pkg:'))
412+
) {
413+
logger.fail(
414+
`"${rawInput}" looks like a vulnerability identifier, not a directory path.\nDid you mean: socket fix ${FLAG_ID} ${rawInput}`,
415+
)
416+
process.exitCode = 1
417+
return
418+
}
419+
420+
let [cwd = '.'] = cli.input
421+
// Note: path.resolve vs .join:
422+
// If given path is absolute then cwd should not affect it.
423+
cwd = path.resolve(process.cwd(), cwd)
424+
425+
// Validate the target directory exists.
426+
if (!existsSync(cwd)) {
427+
logger.fail(`Target directory does not exist: ${cwd}`)
428+
process.exitCode = 1
429+
return
430+
}
431+
403432
if (dryRun) {
404433
logger.log(constants.DRY_RUN_NOT_SAVING)
405434
return
@@ -416,11 +445,6 @@ async function run(
416445

417446
const orgSlug = orgSlugCResult.data
418447

419-
let [cwd = '.'] = cli.input
420-
// Note: path.resolve vs .join:
421-
// If given path is absolute then cwd should not affect it.
422-
cwd = path.resolve(process.cwd(), cwd)
423-
424448
const { spinner } = constants
425449

426450
const includePatterns = cmdFlagValueToArray(include)

0 commit comments

Comments
 (0)