Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cli/commands/run/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,17 @@ export const registerRun = (program: Command) => {
if (!cliOptions.json) console.log(message);
};

if (cliOptions.name?.trim() === '') {
throw new ValidationError('--name must not be empty. Omit the flag to auto-generate a name.');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is outside runCliCommand, which breaks two things:

  1. Telemetry: runCliCommand records failures via trackCommandRun (src/cli/telemetry/cli-command-run.ts). Throwing here bypasses that, so this validation failure is never emitted as a cli.command_run event. Per src/cli/telemetry/README.md, validation errors should be thrown inside the wrapper.

  2. --json output contract: runCliCommand formats errors as { success: false, error: ... } on stdout when --json is set. Throwing outside means Commander's default handler prints plain text to stderr, so agentcore run insights --name "" --json won't produce parseable JSON.

The fix is to move this block inside the runCliCommand callback (a few lines below), next to the existing --lookback-days validation. That's the same pattern used by run ingest at line 672-674.

await runCliCommand('run.job', !!cliOptions.json, async () => {
  if (cliOptions.name !== undefined && cliOptions.name.trim() === '') {
    throw new ValidationError('--name must not be empty. Omit the flag to auto-generate a name.');
  }
  const engine = createJobEngine(new ConfigIO());
  // ...


await runCliCommand('run.job', !!cliOptions.json, async () => {
const engine = createJobEngine(new ConfigIO());

const insightIds = cliOptions.insights ?? ['Builtin.Insight.FailureAnalysis'];
const lookbackDays = cliOptions.lookbackDays ? parseInt(cliOptions.lookbackDays, 10) : undefined;
if (lookbackDays !== undefined && (isNaN(lookbackDays) || lookbackDays < 1 || lookbackDays > 90)) {
throw new Error('--lookback-days must be between 1 and 90');
throw new ValidationError('--lookback-days must be a positive integer between 1 and 90.');
}

const startResult = await engine.start('insights', {
Expand Down
Loading