Skip to content

Commit 0cc518f

Browse files
committed
trim args and log output by default
1 parent adb3d44 commit 0cc518f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

apps/coordinator/src/checkpointer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ export class Checkpointer {
571571
attemptNumber?: number
572572
) {
573573
const containterNameWithAttempt = this.#getRunContainerName(runId, attemptNumber);
574-
const exec = new Exec({ logger: this.#logger, abortSignal, logOutput: true });
574+
const exec = new Exec({ logger: this.#logger, abortSignal });
575575

576576
try {
577577
if (this.opts.forceSimulate || !this.#canCheckpoint) {

apps/coordinator/src/exec.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ interface ExecOptions {
2121
logger?: SimpleLogger;
2222
abortSignal?: AbortSignal;
2323
logOutput?: boolean;
24+
trimArgs?: boolean;
2425
}
2526

2627
export class Exec {
2728
private logger: SimpleLogger;
2829
private abortSignal: AbortSignal | undefined;
30+
2931
private logOutput: boolean;
32+
private trimArgs: boolean;
3033

3134
constructor(opts: ExecOptions) {
3235
this.logger = opts.logger ?? new SimpleLogger();
@@ -38,11 +41,12 @@ export class Exec {
3841
});
3942
}
4043

41-
this.logOutput = opts.logOutput ?? false;
44+
this.logOutput = opts.logOutput ?? true;
45+
this.trimArgs = opts.trimArgs ?? true;
4246
}
4347

44-
async x(command: string, args?: string[], opts?: { neverThrow?: boolean; trimArgs?: boolean }) {
45-
const argsTrimmed = opts?.trimArgs === true ? args?.map((arg) => arg.trim()) : args;
48+
async x(command: string, args?: string[], opts?: { neverThrow?: boolean }) {
49+
const argsTrimmed = this.trimArgs ? args?.map((arg) => arg.trim()) : args;
4650

4751
const commandWithFirstArg = `${command}${argsTrimmed?.length ? ` ${argsTrimmed[0]}` : ""}`;
4852
this.logger.debug(`exec: ${commandWithFirstArg}`, { command, args, argsTrimmed });
@@ -55,31 +59,33 @@ export class Exec {
5559

5660
const output = await result;
5761

62+
const metadata = {
63+
command,
64+
argsRaw: args,
65+
argsTrimmed,
66+
...output,
67+
};
68+
5869
if (this.logOutput) {
59-
this.logger.debug(`output: ${commandWithFirstArg}`, { command, args, argsTrimmed, output });
70+
this.logger.debug(`output: ${commandWithFirstArg}`, metadata);
6071
}
6172

6273
if (opts?.neverThrow) {
6374
return output;
6475
}
6576

6677
if (result.aborted) {
67-
this.logger.error(`aborted: ${commandWithFirstArg}`, { command, args, argsTrimmed, output });
78+
this.logger.error(`aborted: ${commandWithFirstArg}`, metadata);
6879
throw new TinyResult(result);
6980
}
7081

7182
if (result.killed) {
72-
this.logger.error(`killed: ${commandWithFirstArg}`, { command, args, argsTrimmed, output });
83+
this.logger.error(`killed: ${commandWithFirstArg}`, metadata);
7384
throw new TinyResult(result);
7485
}
7586

7687
if (result.exitCode !== 0) {
77-
this.logger.error(`non-zero exit: ${commandWithFirstArg}`, {
78-
command,
79-
args,
80-
argsTrimmed,
81-
output,
82-
});
88+
this.logger.error(`non-zero exit: ${commandWithFirstArg}`, metadata);
8389
throw new TinyResult(result);
8490
}
8591

0 commit comments

Comments
 (0)