Skip to content

Commit 496de92

Browse files
authored
Cleanup debugFn messages (#616)
1 parent a94c026 commit 496de92

21 files changed

+124
-113
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ ${table}
176176
'There was a problem converting the logs to Markdown, please try the `--json` flag',
177177
)
178178
if (isDebug()) {
179-
debugFn('Unexpected error:\n', e)
179+
debugFn('catch: unexpected\n', e)
180180
}
181181
return ''
182182
}

src/commands/ci/fetch-default-org-slug.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function getDefaultOrgSlug(): Promise<CResult<string>> {
1111
const defaultOrgResult = getConfigValueOrUndef('defaultOrg')
1212

1313
if (defaultOrgResult) {
14-
debugFn('Using default org:', defaultOrgResult)
14+
debugFn('use: default org', defaultOrgResult)
1515
return { ok: true, data: defaultOrgResult }
1616
}
1717

@@ -51,7 +51,8 @@ export async function getDefaultOrgSlug(): Promise<CResult<string>> {
5151
}
5252
}
5353

54-
debugFn('Resolved org to:', slug)
54+
debugFn('resolve: org', slug)
55+
5556
return {
5657
ok: true,
5758
message: 'Retrieved default org from server',

src/commands/fix/git.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export async function gitCreateAndPushBranch(
142142
)
143143
return true
144144
} catch (e) {
145-
debugFn('Unexpected error:\n', e)
145+
debugFn('catch: unexpected\n', e)
146146
}
147147
try {
148148
// Will throw with exit code 1 if branch does not exist.
@@ -175,7 +175,7 @@ export async function gitEnsureIdentity(
175175
try {
176176
await spawn('git', ['config', prop, value], stdioIgnoreOptions)
177177
} catch (e) {
178-
debugFn('Unexpected error:\n', e)
178+
debugFn('catch: unexpected\n', e)
179179
}
180180
}
181181
}),
@@ -231,7 +231,8 @@ export async function gitUnstagedModifiedFiles(
231231
const rawFiles = stdout.split('\n') ?? []
232232
return { ok: true, data: rawFiles.map(relPath => normalizePath(relPath)) }
233233
} catch (e) {
234-
debugFn('Unexpected error trying to run git diff --name-only')
234+
debugFn('catch: git diff --name-only failed\n', e)
235+
235236
return {
236237
ok: false,
237238
message: 'Git Error',

src/commands/fix/npm-fix.mts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ export async function npmFix(
126126
: await getAlertsMapFromArborist(arb, getAlertsMapOptions({ limit }))
127127
} catch (e) {
128128
spinner?.stop()
129-
debugFn('API Error thrown:')
130-
debugFn(e)
129+
debugFn('catch: API error\n', e)
131130
return {
132131
ok: false,
133132
message: 'API Error',
@@ -160,9 +159,12 @@ export async function npmFix(
160159
// Process the workspace root last since it will add an override to package.json.
161160
pkgEnvDetails.editablePkgJson.filename!,
162161
]
162+
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) =>
163+
naturalCompare(a[0], b[0]),
164+
)
163165

164166
const handleInstallFail = (): CResult<{ fixed: boolean }> => {
165-
debugFn(`Unexpected condition: ${pkgEnvDetails.agent} install failed.\n`)
167+
debugFn(`fail: ${pkgEnvDetails.agent} install\n`)
166168
logger.dedent()
167169
spinner?.dedent()
168170

@@ -177,9 +179,6 @@ export async function npmFix(
177179

178180
let count = 0
179181

180-
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) =>
181-
naturalCompare(a[0], b[0]),
182-
)
183182
infoEntriesLoop: for (
184183
let i = 0, { length } = sortedInfoEntries;
185184
i < length;
@@ -193,7 +192,7 @@ export async function npmFix(
193192
spinner?.indent()
194193

195194
if (getManifestData(NPM, name)) {
196-
debugFn(`Socket Optimize package exists for ${name}.`)
195+
debugFn(`found: Socket Optimize variant for ${name}`)
197196
}
198197
// eslint-disable-next-line no-await-in-loop
199198
const packument = await fetchPackagePackument(name)
@@ -229,7 +228,7 @@ export async function npmFix(
229228
)
230229

231230
if (!oldVersions.length) {
232-
debugFn(`${name} not found, skipping.\n`)
231+
debugFn(`skip: ${name} not found\n`)
233232
// Skip to next package.
234233
logger.dedent()
235234
spinner?.dedent()
@@ -246,7 +245,7 @@ export async function npmFix(
246245
let hasAnnouncedWorkspace = false
247246
let workspaceLogCallCount = logger.logCallCount
248247
if (isDebug()) {
249-
debugFn(`Checking workspace ${workspace}.`)
248+
debugFn(`check: workspace ${workspace}`)
250249
hasAnnouncedWorkspace = true
251250
workspaceLogCallCount = logger.logCallCount
252251
}
@@ -257,7 +256,7 @@ export async function npmFix(
257256

258257
const node = findPackageNode(actualTree, name, oldVersion)
259258
if (!node) {
260-
debugFn(`${oldId} not found, skipping.`)
259+
debugFn(`skip: ${oldId} not found`)
261260
continue oldVersionsLoop
262261
}
263262

@@ -266,9 +265,7 @@ export async function npmFix(
266265
vulnerableVersionRange,
267266
} of infos.values()) {
268267
if (semver.gte(oldVersion, firstPatchedVersionIdentifier)) {
269-
debugFn(
270-
`${oldId} is >= ${firstPatchedVersionIdentifier}, skipping.`,
271-
)
268+
debugFn(`skip: ${oldId} is >= ${firstPatchedVersionIdentifier}`)
272269
continue infosLoop
273270
}
274271
const newVersion = findBestPatchVersion(
@@ -316,7 +313,7 @@ export async function npmFix(
316313
)
317314
// eslint-disable-next-line no-await-in-loop
318315
if (!(await editablePkgJson.save({ ignoreWhitespace: true }))) {
319-
debugFn(`${workspace}/package.json not changed, skipping.`)
316+
debugFn(`skip: ${workspace}/package.json unchanged`)
320317
// Reset things just in case.
321318
if (isCi) {
322319
// eslint-disable-next-line no-await-in-loop
@@ -392,14 +389,12 @@ export async function npmFix(
392389
await prExistForBranch(repoInfo.owner, repoInfo.repo, branch)
393390
) {
394391
skipPr = true
395-
debugFn(`Branch "${branch}" exists, skipping PR creation.`)
392+
debugFn(`skip: branch "${branch}" exists`)
396393
}
397394
// eslint-disable-next-line no-await-in-loop
398395
else if (await gitRemoteBranchExists(branch, cwd)) {
399396
skipPr = true
400-
debugFn(
401-
`Remote branch "${branch}" exists, skipping PR creation.`,
402-
)
397+
debugFn(`skip: remote branch "${branch}" exists`)
403398
} else if (
404399
// eslint-disable-next-line no-await-in-loop
405400
!(await gitCreateAndPushBranch(

src/commands/fix/open-pr.mts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,16 @@ export async function cleanupOpenPrs(
154154
pull_number: prNum,
155155
state: 'closed',
156156
})
157-
debugFn(`Closed ${prRef} for older version ${prToVersion}.`)
157+
debugFn(`close: ${prRef} for ${prToVersion}`)
158158
// Remove entry from parent object.
159159
context.parent.splice(context.index, 1)
160160
// Mark cache to be saved.
161161
cachesToSave.set(context.cacheKey, context.data)
162162
return null
163163
} catch (e) {
164164
debugFn(
165-
`Failed to close ${prRef}: ${(e as Error)?.message || 'Unknown error'}`,
165+
`fail: close ${prRef}\n`,
166+
(e as Error)?.message || 'unknown error',
166167
)
167168
}
168169
}
@@ -176,7 +177,7 @@ export async function cleanupOpenPrs(
176177
base: match.headRefName,
177178
head: match.baseRefName,
178179
})
179-
debugFn(`Updated stale ${prRef}.`)
180+
debugFn('update: stale', prRef)
180181
// Update entry entry.
181182
if (context.apiType === 'graphql') {
182183
context.entry.mergeStateStatus = 'CLEAN'
@@ -187,7 +188,7 @@ export async function cleanupOpenPrs(
187188
cachesToSave.set(context.cacheKey, context.data)
188189
} catch (e) {
189190
const message = (e as Error)?.message || 'Unknown error'
190-
debugFn(`Failed to update ${prRef}: ${message}`)
191+
debugFn(`fail: update ${prRef} - ${message}`)
191192
}
192193
}
193194
return match
@@ -443,7 +444,7 @@ export async function openPr(
443444
} as OpenPrOptions
444445
// Lazily access constants.ENV.GITHUB_ACTIONS.
445446
if (!constants.ENV.GITHUB_ACTIONS) {
446-
debugFn('Missing GITHUB_ACTIONS environment variable.')
447+
debugFn('miss: GITHUB_ACTIONS env var')
447448
return null
448449
}
449450
const octokit = getOctokit()
@@ -506,6 +507,6 @@ export async function setGitRemoteGitHubRepoUrl(
506507
try {
507508
await spawn('git', ['remote', 'set-url', 'origin', url], stdioIgnoreOptions)
508509
} catch (e) {
509-
debugFn('Unexpected error:\n', e)
510+
debugFn('catch: unexpected\n', e)
510511
}
511512
}

src/commands/fix/pnpm-fix.mts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ export async function pnpmFix(
202202
)
203203
} catch (e) {
204204
spinner?.stop()
205-
debugFn('Unexpected Socket batch PURL API error:')
206-
debugFn(e)
205+
debugFn('fail: PURL API\n', e)
207206
return {
208207
ok: false,
209208
message: 'API Error',
@@ -236,6 +235,9 @@ export async function pnpmFix(
236235
// Process the workspace root last since it will add an override to package.json.
237236
pkgEnvDetails.editablePkgJson.filename!,
238237
]
238+
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) =>
239+
naturalCompare(a[0], b[0]),
240+
)
239241

240242
const handleInstallFail = (): CResult<{ fixed: boolean }> => {
241243
logger.dedent()
@@ -252,9 +254,6 @@ export async function pnpmFix(
252254

253255
let count = 0
254256

255-
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) =>
256-
naturalCompare(a[0], b[0]),
257-
)
258257
infoEntriesLoop: for (
259258
let i = 0, { length } = sortedInfoEntries;
260259
i < length;
@@ -268,7 +267,7 @@ export async function pnpmFix(
268267
spinner?.indent()
269268

270269
if (getManifestData(NPM, name)) {
271-
debugFn(`Socket Optimize package exists for ${name}.`)
270+
debugFn(`found: Socket Optimize variant for ${name}`)
272271
}
273272
// eslint-disable-next-line no-await-in-loop
274273
const packument = await fetchPackagePackument(name)
@@ -326,7 +325,7 @@ export async function pnpmFix(
326325
)
327326

328327
if (!oldVersions.length) {
329-
debugFn(`${name} not found, skipping.\n`)
328+
debugFn(`skip: ${name} not found\n`)
330329
// Skip to next package.
331330
logger.dedent()
332331
spinner?.dedent()
@@ -351,7 +350,7 @@ export async function pnpmFix(
351350
let hasAnnouncedWorkspace = false
352351
let workspaceLogCallCount = logger.logCallCount
353352
if (isDebug()) {
354-
debugFn(`Checking workspace ${workspace}.`)
353+
debugFn(`check: workspace ${workspace}`)
355354
hasAnnouncedWorkspace = true
356355
workspaceLogCallCount = logger.logCallCount
357356
}
@@ -362,17 +361,15 @@ export async function pnpmFix(
362361

363362
const node = findPackageNode(actualTree, name, oldVersion)
364363
if (!node) {
365-
debugFn(`${oldId} not found, skipping.`)
364+
debugFn(`skip: ${oldId} not found`)
366365
continue oldVersionsLoop
367366
}
368367
infosLoop: for (const {
369368
firstPatchedVersionIdentifier,
370369
vulnerableVersionRange,
371370
} of infos.values()) {
372371
if (semver.gte(oldVersion, firstPatchedVersionIdentifier)) {
373-
debugFn(
374-
`${oldId} is >= ${firstPatchedVersionIdentifier}, skipping.`,
375-
)
372+
debugFn(`skip: ${oldId} is >= ${firstPatchedVersionIdentifier}`)
376373
continue infosLoop
377374
}
378375
const newVersion = findBestPatchVersion(
@@ -460,7 +457,7 @@ export async function pnpmFix(
460457
)
461458
// eslint-disable-next-line no-await-in-loop
462459
if (!(await editablePkgJson.save({ ignoreWhitespace: true }))) {
463-
debugFn(`${workspace}/package.json unchanged, skipping.`)
460+
debugFn(`skip: ${workspace}/package.json unchanged`)
464461
// Reset things just in case.
465462
if (isCi) {
466463
// eslint-disable-next-line no-await-in-loop
@@ -556,14 +553,12 @@ export async function pnpmFix(
556553
await prExistForBranch(repoInfo.owner, repoInfo.repo, branch)
557554
) {
558555
skipPr = true
559-
debugFn(`Branch "${branch}" exists, skipping PR creation.`)
556+
debugFn(`skip: branch "${branch}" exists`)
560557
}
561558
// eslint-disable-next-line no-await-in-loop
562559
else if (await gitRemoteBranchExists(branch, cwd)) {
563560
skipPr = true
564-
debugFn(
565-
`Remote branch "${branch}" exists, skipping PR creation.`,
566-
)
561+
debugFn(`skip: remote branch "${branch}" exists`)
567562
} else if (
568563
// eslint-disable-next-line no-await-in-loop
569564
!(await gitCreateAndPushBranch(
@@ -734,5 +729,6 @@ export async function pnpmFix(
734729

735730
spinner?.stop()
736731

737-
return { ok: true, data: { fixed: true } } // or, did we change anything?
732+
// Or, did we change anything?
733+
return { ok: true, data: { fixed: true } }
738734
}

src/commands/install/setup-tab-completion.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export async function setupTabCompletion(targetName: string): Promise<
3131

3232
// Target dir is something like ~/.local/share/socket/settings/completion (linux)
3333
const targetDir = path.dirname(targetPath)
34-
debugFn('Target Path:', targetPath, ', Target Dir:', targetDir)
34+
debugFn('target: path + dir', targetPath, targetDir)
3535

3636
if (!fs.existsSync(targetDir)) {
37-
debugFn('Dir does not exist, creating it now...')
37+
debugFn('create: target dir')
3838
fs.mkdirSync(targetDir, { recursive: true })
3939
}
4040

src/commands/optimize/update-lockfile.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export async function updateLockfile(
4444
}
4545
} catch (e) {
4646
spinner?.stop()
47-
debugFn(e)
47+
48+
debugFn('fail: update\n', e)
49+
4850
return {
4951
ok: false,
5052
message: 'Update failed',

src/commands/repos/fetch-list-all-repos.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function fetchListAllRepos({
4343
'list of repositories',
4444
)
4545
if (!result.ok) {
46-
debugFn('At least one fetch failed, bailing...', result)
46+
debugFn('fail: fetch repo\n', result)
4747
return result
4848
}
4949

0 commit comments

Comments
 (0)