2323import java .util .Locale ;
2424import java .util .Map ;
2525import java .util .Objects ;
26+ import java .util .UUID ;
2627import lombok .Getter ;
28+ import lombok .extern .slf4j .Slf4j ;
2729import org .apache .commons .exec .CommandLine ;
2830
2931/**
3537 * @since 3.0.0
3638 */
3739@ Getter
40+ @ Slf4j
3841public class OpenCliExecutor implements AutoCloseable {
3942 private final OpenCliProperties properties ;
4043 private final OpenCliProcessRuntime processRuntime ;
@@ -198,8 +201,10 @@ private int effectiveCaptureLimit(int streamLimit) {
198201 }
199202
200203 private OpenCliResult complete (SubprocessExecutionSupport .RunSession session ) {
201- String stdout = new String (session .getStdout ().toByteArray (), StandardCharsets .UTF_8 );
202- String stderr = new String (session .getStderr ().toByteArray (), StandardCharsets .UTF_8 );
204+ byte [] stdoutBytes = session .getStdout ().toByteArray ();
205+ byte [] stderrBytes = session .getStderr ().toByteArray ();
206+ String stdout = new String (stdoutBytes , StandardCharsets .UTF_8 );
207+ String stderr = new String (stderrBytes , StandardCharsets .UTF_8 );
203208 OpenCliExecutionDetails details = session .getExecutionDetails ();
204209 TerminationReason reason = details .getTerminationReason ();
205210 Integer exit = session .getObservedExitCode ();
@@ -211,18 +216,24 @@ private OpenCliResult complete(SubprocessExecutionSupport.RunSession session) {
211216 .errorEnvelope (success ? null : OpenCliErrorDecoder .decode (stderr , exit ,
212217 reason != TerminationReason .PROCESS_EXIT || !details .isStreamsDrained () || details .isStderrTruncated ()))
213218 .build ();
214- if (success ) { return result ; }
219+ if (success ) {
220+ return result ;
221+ }
222+ String correlationId = UUID .randomUUID ().toString ();
223+ String diagnosticSuffix = " correlationId=" + correlationId ;
224+ log .debug ("OpenCLI process failed correlationId={} reason={} exitCode={} stdoutBytes={} stderrBytes={}" ,
225+ correlationId , reason , exit , stdoutBytes .length , stderrBytes .length );
215226 if (reason == TerminationReason .QUEUE_TIMEOUT || reason == TerminationReason .EXECUTION_TIMEOUT ) {
216- throw new OpenCliTimeoutException ("OpenCLI deadline exceeded: " + reason , result );
227+ throw new OpenCliTimeoutException ("OpenCLI deadline exceeded: " + reason + diagnosticSuffix , result );
217228 }
218229 if (reason == TerminationReason .SPAWN_FAILED ) {
219- throw new OpenCliExecutableFailureException ("OpenCLI process could not be started" , null , result );
230+ throw new OpenCliExecutableFailureException ("OpenCLI process could not be started" + diagnosticSuffix , null , result );
220231 }
221232 if (reason == TerminationReason .PROCESS_EXIT && exit != null && exit != 0 ) {
222- throw new OpenCliNonZeroExitException ("OpenCLI returned nonzero exitCode=" + exit , result );
233+ throw new OpenCliNonZeroExitException ("OpenCLI returned nonzero exitCode=" + exit + diagnosticSuffix , result );
223234 }
224235 // Native I/O errors may include executable paths or other invocation data.
225- throw new OpenCliException ("OpenCLI execution ended: " + reason , result );
236+ throw new OpenCliException ("OpenCLI execution ended: " + reason + diagnosticSuffix , result );
226237 }
227238
228239 private File resolveWorkingDirectory () {
0 commit comments