fix(execute-command): fix $-pattern substitution, maxBuffer vs timeout detection, bestPractices text

This commit is contained in:
Waleed Latif
2026-03-05 12:51:02 -08:00
parent 6802245a8a
commit 2a8aae68c5
2 changed files with 20 additions and 3 deletions

View File

@@ -131,7 +131,7 @@ function resolveTagVariables(
stringValue = String(result.value)
}
resolved = resolved.replace(new RegExp(escapeRegExp(match), 'g'), stringValue)
resolved = resolved.replace(new RegExp(escapeRegExp(match), 'g'), () => stringValue)
}
return resolved
@@ -160,6 +160,7 @@ interface CommandResult {
stderr: string
exitCode: number
timedOut: boolean
maxBufferExceeded: boolean
}
/**
@@ -182,12 +183,14 @@ function executeCommand(
(error, stdout, stderr) => {
if (error) {
const killed = error.killed ?? false
const isMaxBuffer = killed && /maxBuffer/.test(error.message ?? '')
const exitCode = typeof error.code === 'number' ? error.code : 1
resolve({
stdout: stdout.trimEnd(),
stderr: stderr.trimEnd(),
exitCode,
timedOut: killed,
timedOut: killed && !isMaxBuffer,
maxBufferExceeded: isMaxBuffer,
})
return
}
@@ -196,6 +199,7 @@ function executeCommand(
stderr: stderr.trimEnd(),
exitCode: 0,
timedOut: false,
maxBufferExceeded: false,
})
}
)
@@ -206,6 +210,7 @@ function executeCommand(
stderr: err.message,
exitCode: 1,
timedOut: false,
maxBufferExceeded: false,
})
})
})
@@ -297,6 +302,18 @@ export async function POST(req: NextRequest) {
})
}
if (result.maxBufferExceeded) {
return NextResponse.json({
success: false,
output: {
stdout: result.stdout,
stderr: result.stderr,
exitCode: result.exitCode,
},
error: `Command output exceeded maximum buffer size of ${MAX_BUFFER / 1024 / 1024}MB`,
})
}
return NextResponse.json({
success: true,
output: {

View File

@@ -16,7 +16,7 @@ export const ExecuteCommandBlock: BlockConfig<ExecuteCommandOutput> = {
- Use <blockName.output> syntax to reference outputs from other blocks.
- Use {{ENV_VAR}} syntax to reference environment variables.
- The working directory defaults to the server process directory if not specified.
- A non-zero exit code is treated as an error. Use || true to suppress errors if needed.
- A non-zero exit code is returned as data (exitCode > 0), not treated as a workflow error. Use a Condition block to branch on exitCode if needed.
`,
docsLink: 'https://docs.sim.ai/blocks/execute-command',
category: 'blocks',