Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 4492fee

Browse files
authored
feat: add verbose mode to example runner and extend error handling (#125)
1 parent e567330 commit 4492fee

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

example

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ $app = (new SingleCommandApplication('LLM Chain Example Runner'))
4646
sleep(1);
4747
foreach ($exampleRuns as $run) {
4848
if ('running' === $run['state'] && !$run['process']->isRunning()) {
49-
$result = $run['process']->isSuccessful() ? '<info>Finished</info>'
50-
: (1 === $run['process']->getExitCode() ? '<error>Failed</error>' : '<comment>Skipped</comment>');
49+
$emptyOutput = 0 === strlen(trim($run['process']->getOutput()));
50+
$success = $run['process']->isSuccessful() && !$emptyOutput;
51+
$result = $success ? '<info>Finished</info>'
52+
: (1 === $run['process']->getExitCode() || $emptyOutput ? '<error>Failed</error>' : '<comment>Skipped</comment>');
5153
$run['section']->overwrite(sprintf('Example %s: %s', $run['example']->getFilename(), $result));
5254
$run['state'] = 'finished';
55+
if ($output->isVerbose()) {
56+
$exampleOutput = $emptyOutput ? 'Output was empty' : $run['process']->getOutput();
57+
$exampleOutput = strlen($exampleOutput) <= 100 ? $exampleOutput : substr($exampleOutput, 0, 100).'...';
58+
$run['section']->writeln(
59+
sprintf('<%s>%s</>', $success ? 'fg=#999999' : 'fg=red', trim($exampleOutput))
60+
);
61+
}
5362
}
5463
}
5564
}

0 commit comments

Comments
 (0)