Skip to content

Commit 10f2dfc

Browse files
committed
fix: improve --dry-run validation and add Node.js error filtering
- Skip API token validation in --dry-run mode for proper input checking - Add error filtering to remove Node.js stack traces in production - Make the CLI feel more professional, less like a Node.js app - Use console.log for critical JSON error output to bypass logger silencing - Stack traces only shown in DEBUG/development mode
1 parent 041b9b0 commit 10f2dfc

21 files changed

+254
-20
lines changed

src/cli.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
formatErrorForTerminal,
3939
} from './utils/error-display.mts'
4040
import { captureException } from './utils/errors.mts'
41+
import { installErrorFiltering } from './utils/error-filter.mts'
4142
import { meowWithSubcommands } from './utils/meow-with-subcommands.mts'
4243
import { isSeaBinary } from './utils/sea.mts'
4344
import { serializeResultJson } from './utils/serialize-result-json.mts'
@@ -46,6 +47,9 @@ import { scheduleUpdateCheck } from './utils/update-manager.mts'
4647

4748
const __filename = fileURLToPath(import.meta.url)
4849

50+
// Install error filtering to clean up Node.js stack traces
51+
installErrorFiltering()
52+
4953
// Check for --no-log or --json flag early and silence logger if present
5054
// When --json is set, we want clean JSON output without any logger noise
5155
const noLog =

src/commands/audit-log/cmd-audit-log.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async function run(
181181
const hasApiToken = hasDefaultApiToken()
182182
const wasValidAuth = checkCommandInput(outputKind, {
183183
nook: true,
184-
test: hasApiToken,
184+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
185185
message: 'This command requires a Socket API token for access',
186186
fail: 'try `socket login`',
187187
})

src/commands/organization/cmd-organization-dependencies.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async function run(
104104
const hasApiToken = hasDefaultApiToken()
105105
const wasValidAuth = checkCommandInput(outputKind, {
106106
nook: true,
107-
test: hasApiToken,
107+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
108108
message: 'This command requires a Socket API token for access',
109109
fail: 'try `socket login`',
110110
})

src/commands/organization/cmd-organization-list.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async function run(
9393
const hasApiToken = hasDefaultApiToken()
9494
const wasValidAuth = checkCommandInput(outputKind, {
9595
nook: true,
96-
test: hasApiToken,
96+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
9797
message: 'This command requires a Socket API token for access',
9898
fail: 'try `socket login`',
9999
})

src/commands/organization/cmd-organization-policy-license.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async function run(
109109
},
110110
{
111111
nook: true,
112-
test: hasApiToken,
112+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
113113
message: 'This command requires a Socket API token for access',
114114
fail: 'try `socket login`',
115115
},

src/commands/organization/cmd-organization-policy-security.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async function run(
125125
const hasApiToken = hasDefaultApiToken()
126126
const wasValidAuth = checkCommandInput(outputKind, {
127127
nook: true,
128-
test: hasApiToken,
128+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
129129
message: 'This command requires a Socket API token for access',
130130
fail: 'try `socket login`',
131131
})

src/commands/organization/cmd-organization-quota.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function run(
8383
const hasApiToken = hasDefaultApiToken()
8484
const wasValidAuth = checkCommandInput(outputKind, {
8585
nook: true,
86-
test: hasApiToken,
86+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
8787
message: 'This command requires a Socket API token for access',
8888
fail: 'try `socket login`',
8989
})

src/commands/package/cmd-package-score.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async function run(
133133
const hasApiToken = hasDefaultApiToken()
134134
const wasValidAuth = checkCommandInput(outputKind, {
135135
nook: true,
136-
test: hasApiToken,
136+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
137137
message: 'This command requires a Socket API token for access',
138138
fail: 'try `socket login`',
139139
})

src/commands/repository/cmd-repository-update.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async function run(
145145
},
146146
{
147147
nook: true,
148-
test: hasApiToken,
148+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
149149
message: 'This command requires a Socket API token for access',
150150
fail: 'try `socket login`',
151151
},

src/commands/scan/cmd-scan-create.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ async function run(
495495
// Auth check (only in non-dry-run mode)
496496
const wasValidAuth = checkCommandInput(outputKind, {
497497
nook: true,
498-
test: hasApiToken,
498+
test: dryRun || hasApiToken, // Skip API token check in dry-run mode
499499
message: 'This command requires a Socket API token for access',
500500
fail: 'try `socket login`',
501501
})

0 commit comments

Comments
 (0)