@orchagent/cli 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/run.js +28 -10
- package/package.json +1 -1
package/dist/commands/run.js
CHANGED
|
@@ -390,29 +390,47 @@ async function executeBundleAgent(config, org, agentName, version, agentData, ar
|
|
|
390
390
|
stderr += text;
|
|
391
391
|
process.stderr.write(text);
|
|
392
392
|
});
|
|
393
|
-
await new Promise((resolve
|
|
393
|
+
const exitCode = await new Promise((resolve) => {
|
|
394
394
|
proc.on('close', (code) => {
|
|
395
|
-
|
|
396
|
-
reject(new errors_1.CliError(`Agent exited with code ${code}`));
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
resolve();
|
|
400
|
-
}
|
|
395
|
+
resolve(code ?? 1);
|
|
401
396
|
});
|
|
402
397
|
proc.on('error', (err) => {
|
|
403
|
-
|
|
398
|
+
process.stderr.write(`Error running agent: ${err.message}\n`);
|
|
399
|
+
resolve(1);
|
|
404
400
|
});
|
|
405
401
|
});
|
|
406
|
-
//
|
|
402
|
+
// Handle output - check for errors in stdout even on failure
|
|
407
403
|
if (stdout.trim()) {
|
|
408
404
|
try {
|
|
409
405
|
const result = JSON.parse(stdout.trim());
|
|
406
|
+
// Check if it's an error response
|
|
407
|
+
if (exitCode !== 0 && typeof result === 'object' && result !== null && 'error' in result) {
|
|
408
|
+
throw new errors_1.CliError(`Agent error: ${result.error}`);
|
|
409
|
+
}
|
|
410
|
+
if (exitCode !== 0) {
|
|
411
|
+
// Non-zero exit but output isn't an error object - show it and fail
|
|
412
|
+
(0, output_1.printJson)(result);
|
|
413
|
+
throw new errors_1.CliError(`Agent exited with code ${exitCode}`);
|
|
414
|
+
}
|
|
415
|
+
// Success - print result
|
|
410
416
|
(0, output_1.printJson)(result);
|
|
411
417
|
}
|
|
412
|
-
catch {
|
|
418
|
+
catch (err) {
|
|
419
|
+
if (err instanceof errors_1.CliError)
|
|
420
|
+
throw err;
|
|
413
421
|
// Not JSON, print as-is
|
|
414
422
|
process.stdout.write(stdout);
|
|
423
|
+
if (exitCode !== 0) {
|
|
424
|
+
throw new errors_1.CliError(`Agent exited with code ${exitCode}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
else if (exitCode !== 0) {
|
|
429
|
+
// No stdout, check stderr
|
|
430
|
+
if (stderr.trim()) {
|
|
431
|
+
throw new errors_1.CliError(`Agent error: ${stderr.trim()}`);
|
|
415
432
|
}
|
|
433
|
+
throw new errors_1.CliError(`Agent exited with code ${exitCode} (no output)`);
|
|
416
434
|
}
|
|
417
435
|
}
|
|
418
436
|
finally {
|