Skip to content

fix(cli): align utils/ miscellaneous error messages with 4-ingredient strategy#1260

Open
John-David Dalton (jdalton) wants to merge 3 commits intomainfrom
jdd/error-msg-utils-misc
Open

fix(cli): align utils/ miscellaneous error messages with 4-ingredient strategy#1260
John-David Dalton (jdalton) wants to merge 3 commits intomainfrom
jdd/error-msg-utils-misc

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 22, 2026

Summary

Final PR in the error-message series. Covers everything not already touched by #1255#1259: flags.mts, utils/basics, utils/config, utils/fs, utils/git, utils/npm, utils/promise, utils/terminal.

~14 messages across 9 source files + 3 test files. Full unit suite (5225 tests) passes.

What's fixed

Flag validation (flags.mts)

Before: Invalid value for --max-old-space-size: abc
After: --max-old-space-size must be a non-negative integer in megabytes (saw: "abc"); pass a whole number like --max-old-space-size=4096 for 4GB

Same for --max-semi-space-size.

Env-var decode (utils/config.mts)

SOCKET_CLI_CONFIG is base64-encoded JSON. When it decodes to garbage, you now get told how to re-encode (echo '{...}' | base64) and what the symptom means (replacement characters).

SEA VFS extraction (utils/basics/vfs-extract.mts, 4 throws)

Same treatment as the other SEA paths in #1256/#1258 — name the missing path, the exit code, point at "rebuild the SEA binary" as the fix.

Library-level guards (4 throws in promise/queue, npm/spec, git/operations, fs/path-resolve)

Each now names the offending value/path and suggests a concrete repair. Example for the npm path walk cycle:

Before: path traversal exceeded maximum iterations of 100
After: npm path resolution walked 100 directories without finding lib/node_modules/npm starting from "<input>" (current: "<where-we-are>"); check for a circular symlink or corrupt node install

GitLab provider (utils/git/gitlab-provider.mts, 2 throws)

  • Missing-token error now points at https://gitlab.com/-/user_settings/personal_access_tokens and specifies the api scope.
  • Retry-exhaustion error names the owner/repo/head refs and the retry count.

Native-module load (utils/terminal/iocraft.mts)

Before: Failed to load iocraft native module: <err>\nMake sure @socketaddon/iocraft is installed...
After: could not load @socketaddon/iocraft native module (<msg>); reinstall socket-cli to pull the prebuilt for your platform, or check that your platform (<plat>-<arch>) has a published prebuilt

Skipped (already informative)

  • github-provider.mts pass-through errors (forward inner CResult cause/message)
  • gitlab-provider.mts try/catch wrappers using formatErrorWithDetail (inner error already contextual)
  • process.exit called sentinels in npm/pnpm/yarn/with-subcommands paths (test harness re-raise markers, not user-facing)

Tests

  • test/unit/utils/promise/queue.test.mts (2 assertions)
  • test/unit/utils/npm/spec.test.mts (2 assertions)
  • test/unit/utils/git/gitlab-provider.test.mts (3 assertions)

Full suite: 5225/5225 passes.

Series complete

This closes out the 4-ingredient error-message cleanup on packages/cli/src/:

Test plan

  • CI green
  • Sanity: socket --max-old-space-size=abc scan ... prints the new message
  • Sanity: unset GITLAB_TOKEN && socket fix with a GitLab repo triggers the new token-missing error

Note

Low Risk
Low risk: changes are limited to improving thrown error messages (plus minor helper imports) and updating unit tests to match, with no behavioral logic changes beyond message text.

Overview
Improves user-facing error messages across the CLI for several failure paths (flag validation, config base64 decode, basics SEA/VFS extraction and tool validation, npm path resolution, GitLab MR creation/token lookup, git executable discovery, npm spec→PURL conversion, PromiseQueue parameter validation, and iocraft native module loading) by adding concrete context (offending values/paths, exit codes) and suggested remediation steps.

Updates related unit tests to assert the new, more descriptive error outputs.

Reviewed by Cursor Bugbot for commit 579638d. Configure here.

… strategy

Final PR in the error-message series. Covers everything not already
touched by #1255-#1259: utils/basics, utils/config, utils/fs,
utils/git, utils/npm, utils/promise, utils/terminal, and the flags
module at the root of the CLI tree.

Sources:
- flags.mts: 2 throws (--max-old-space-size, --max-semi-space-size)
  — name the flag, show the offending value, suggest a concrete
  megabyte value.
- utils/config.mts: 1 throw (SOCKET_CLI_CONFIG base64 decode) —
  explains the replacement-character symptom and how to re-encode.
- utils/basics/vfs-extract.mts: 4 throws (SEA VFS extraction for
  Python + security tools) — name the missing paths, the exit
  codes, and point at the "rebuild the SEA binary" fix.
- utils/promise/queue.mts: 1 throw (PromiseQueue concurrency guard)
  — show the offending value and suggest 4/8.
- utils/npm/spec.mts: 1 throw (PURL conversion) — show the input,
  state what a valid npm spec looks like.
- utils/git/operations.mts: 1 throw (git-not-on-PATH) — point at
  install and the local-path env-var override.
- utils/git/gitlab-provider.mts: 2 throws (no token, PR creation
  after retries) — name the token scope, the retry count, the
  repo/head refs.
- utils/fs/path-resolve.mts: 1 throw (npm path-walk iteration cap)
  — name the start path, current directory, and what usually
  causes the cycle (symlinks).
- utils/terminal/iocraft.mts: 1 throw (native-module load failure)
  — show the underlying error and the offending platform/arch
  triple.

Skipped (already informative):
- github-provider.mts pass-through errors (forward inner CResult
  cause/message)
- gitlab-provider.mts try/catch wrappers that call
  formatErrorWithDetail (inner error has context)
- 'process.exit called' sentinel throws in npm/pnpm/yarn/with-
  subcommands paths (test harness re-raise markers, not user-facing)

Tests updated:
- test/unit/utils/promise/queue.test.mts (2 assertions)
- test/unit/utils/npm/spec.test.mts (2 assertions)
- test/unit/utils/git/gitlab-provider.test.mts (3 assertions)

Full suite (343 files / 5225 tests) passes.

Completes the series: #1255 (commands/) → #1256 (utils/dlx/) →
#1257 (utils/update + utils/command/) → #1258 (env/ + constants/) →
#1259 (test/) → this.
Comment thread packages/cli/src/utils/git/gitlab-provider.mts Outdated
Comment thread packages/cli/src/utils/git/operations.mts Outdated
Comment thread packages/cli/src/utils/terminal/iocraft.mts Outdated
Comment thread packages/cli/src/utils/git/gitlab-provider.mts Outdated
Four issues flagged by Cursor bugbot on #1260:

1. (Medium) gitlab-provider.mts: error said 'check GL_TOKEN permissions'
   but the actual env var is GITLAB_TOKEN (as the same file's getGitLabToken
   confirms). Fixed to GITLAB_TOKEN.

2. (Medium) git/operations.mts: error suggested 'set SOCKET_CLI_GIT_PATH
   to point at a specific binary' — that env var is not read anywhere.
   Removed the false suggestion; kept the real fix (install git and put
   it on PATH) with package-manager examples.

3. (Low) terminal/iocraft.mts: '(e as Error).message' evaluates to
   undefined when a non-Error is thrown. Switched to
   'e instanceof Error ? e.message : String(e)' for safe stringification.

4. (Low) gitlab-provider.mts: error said 'after ${retries} retries' but
   the loop runs attempt 1..retries inclusive — retries is the total
   attempt count, not retries beyond the first. Reworded to 'attempts'.
   Matching test assertions updated.

Caught by #1260 bugbot review.
John-David Dalton (jdalton) added a commit that referenced this pull request Apr 22, 2026
Switch `(e as Error).message` to `e instanceof Error ? e.message : String(e)` so that when a non-Error value is thrown (strings, objects, null) the error message stays informative instead of becoming 'undefined'.

Same fix as applied to #1260 (iocraft.mts) after Cursor bugbot flagged the pattern on that PR.
John-David Dalton (jdalton) added a commit that referenced this pull request Apr 22, 2026
Switch `(e as Error).message` to `e instanceof Error ? e.message : String(e)` so that when a non-Error value is thrown (strings, objects, null) the error message stays informative instead of becoming 'undefined'.

Same fix as applied to #1260 (iocraft.mts) after Cursor bugbot flagged the pattern on that PR.
John-David Dalton (jdalton) added a commit that referenced this pull request Apr 22, 2026
Switch `(e as Error).message` to `e instanceof Error ? e.message : String(e)` so that when a non-Error value is thrown (strings, objects, null) the error message stays informative instead of becoming 'undefined'.

Same fix as applied to #1260 (iocraft.mts) after Cursor bugbot flagged the pattern on that PR.
John-David Dalton (jdalton) added a commit that referenced this pull request Apr 22, 2026
Switch `(e as Error).message` to `e instanceof Error ? e.message : String(e)` so that when a non-Error value is thrown (strings, objects, null) the error message stays informative instead of becoming 'undefined'.

Same fix as applied to #1260 (iocraft.mts) after Cursor bugbot flagged the pattern on that PR.
- basics/vfs-extract.mts: missingTools list now renders as prose
  via joinAnd('a, b, and c').
- terminal/iocraft.mts: inline `e instanceof Error ? e.message :
  String(e)` swapped for getErrorCause(e). require() of a native
  binding can throw non-Error values, so the safe-stringify with
  UNKNOWN_ERROR fallback is correct here.

No behavior change for Error throws.
@socket-security-staging
Copy link
Copy Markdown

socket-security-staging Bot commented Apr 23, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@jdalton
Copy link
Copy Markdown
Contributor Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 579638d. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant