Skip to content

Commit 4435869

Browse files
committed
logging: log tryRun() process invocations by default
But _don't_ log isValidSamLocation(), it's too noisy.
1 parent 34813b6 commit 4435869

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/shared/sam/cli/samCliLocator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class DefaultSamCliLocationProvider implements SamCliLocationProvider {
2222

2323
/** Checks that the given `sam` actually works by invoking `sam --version`. */
2424
private static async isValidSamLocation(samPath: string) {
25-
return await SystemUtilities.tryRun(samPath, ['--version'], true, 'SAM CLI')
25+
return await SystemUtilities.tryRun(samPath, ['--version'], 'no', 'SAM CLI')
2626
}
2727

2828
/**

src/shared/systemUtilities.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ export class SystemUtilities {
192192
* @param doLog log failures
193193
* @param expected output must contain this string
194194
*/
195-
public static async tryRun(p: string, args: string[], doLog?: boolean, expected?: string): Promise<boolean> {
196-
const proc = new ChildProcess(p, args)
195+
public static async tryRun(p: string, args: string[], logging: 'yes' | 'no' | 'noresult' = 'yes', expected?: string): Promise<boolean> {
196+
const proc = new ChildProcess(p, args, { logging: 'no' })
197197
const r = await proc.run()
198-
if (r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected))) {
199-
return true
198+
const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected))
199+
if (logging === 'noresult') {
200+
getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc)
201+
} else if (logging !== 'no') {
202+
getLogger().info('tryRun: %s: %s %O', ok ? 'ok' : 'failed', proc, proc.result())
200203
}
201-
if (doLog) {
202-
getLogger().warn('tryRun: failed: %s %O', proc, proc.result())
203-
}
204-
return false
204+
return ok
205205
}
206206

207207
/**
@@ -263,7 +263,7 @@ export class SystemUtilities {
263263

264264
for (const tsc of tscPaths) {
265265
// Try to run "tsc -v".
266-
if (await SystemUtilities.tryRun(tsc, ['-v'], false, 'Version')) {
266+
if (await SystemUtilities.tryRun(tsc, ['-v'], 'yes', 'Version')) {
267267
return tsc
268268
}
269269
}
@@ -292,7 +292,7 @@ export class SystemUtilities {
292292
if (!p || ('ssh' !== p && !fs.existsSync(p))) {
293293
continue
294294
}
295-
if (await SystemUtilities.tryRun(p, ['-G', 'x'])) {
295+
if (await SystemUtilities.tryRun(p, ['-G', 'x'], 'noresult' /* "ssh -G" prints quasi-sensitive info. */)) {
296296
SystemUtilities.sshPath = p
297297
return p
298298
}

0 commit comments

Comments
 (0)