mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:50:43 +00:00
refactor(hooks): dedupe command result formatting
This commit is contained in:
@@ -23,13 +23,17 @@ function trimOutput(value: string): string {
|
|||||||
return `${trimmed.slice(0, MAX_OUTPUT_CHARS)}…`;
|
return `${trimmed.slice(0, MAX_OUTPUT_CHARS)}…`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCommandFailure(command: string, result: SpawnResult): string {
|
function formatCommandResultInternal(
|
||||||
|
command: string,
|
||||||
|
result: SpawnResult,
|
||||||
|
statusLabel: "failed" | "exited",
|
||||||
|
): string {
|
||||||
const code = result.code ?? "null";
|
const code = result.code ?? "null";
|
||||||
const signal = result.signal ? `, signal=${result.signal}` : "";
|
const signal = result.signal ? `, signal=${result.signal}` : "";
|
||||||
const killed = result.killed ? ", killed=true" : "";
|
const killed = result.killed ? ", killed=true" : "";
|
||||||
const stderr = trimOutput(result.stderr);
|
const stderr = trimOutput(result.stderr);
|
||||||
const stdout = trimOutput(result.stdout);
|
const stdout = trimOutput(result.stdout);
|
||||||
const lines = [`${command} failed (code=${code}${signal}${killed})`];
|
const lines = [`${command} ${statusLabel} (code=${code}${signal}${killed})`];
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
lines.push(`stderr: ${stderr}`);
|
lines.push(`stderr: ${stderr}`);
|
||||||
}
|
}
|
||||||
@@ -39,20 +43,12 @@ function formatCommandFailure(command: string, result: SpawnResult): string {
|
|||||||
return lines.join("\n");
|
return lines.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatCommandFailure(command: string, result: SpawnResult): string {
|
||||||
|
return formatCommandResultInternal(command, result, "failed");
|
||||||
|
}
|
||||||
|
|
||||||
function formatCommandResult(command: string, result: SpawnResult): string {
|
function formatCommandResult(command: string, result: SpawnResult): string {
|
||||||
const code = result.code ?? "null";
|
return formatCommandResultInternal(command, result, "exited");
|
||||||
const signal = result.signal ? `, signal=${result.signal}` : "";
|
|
||||||
const killed = result.killed ? ", killed=true" : "";
|
|
||||||
const stderr = trimOutput(result.stderr);
|
|
||||||
const stdout = trimOutput(result.stdout);
|
|
||||||
const lines = [`${command} exited (code=${code}${signal}${killed})`];
|
|
||||||
if (stderr) {
|
|
||||||
lines.push(`stderr: ${stderr}`);
|
|
||||||
}
|
|
||||||
if (stdout) {
|
|
||||||
lines.push(`stdout: ${stdout}`);
|
|
||||||
}
|
|
||||||
return lines.join("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatJsonParseFailure(command: string, result: SpawnResult, err: unknown): string {
|
function formatJsonParseFailure(command: string, result: SpawnResult, err: unknown): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user