@@ -386,7 +386,12 @@ public function createRuntime(
386386 );
387387
388388 if (!$ status ) {
389- throw new ExecutorException (ExecutorException::RUNTIME_FAILED , 'Failed to create runtime: ' . $ stdout );
389+ $ message = \trim ($ stdout );
390+
391+ throw new ExecutorException (
392+ ExecutorException::BUILD_FAILED ,
393+ $ message === '' ? 'Build command failed. ' : $ message
394+ );
390395 }
391396
392397 if ($ version === 'v2 ' ) {
@@ -398,6 +403,14 @@ public function createRuntime(
398403 } elseif (!$ cacheEnabled ) {
399404 $ output = Logs::get ($ runtimeName );
400405 }
406+ } catch (ExecutorException $ err ) {
407+ throw $ err ;
408+ } catch (OrchestrationException $ err ) {
409+ throw new ExecutorException (
410+ ExecutorException::BUILD_FAILED ,
411+ 'Build command failed. ' ,
412+ previous: $ err
413+ );
401414 } catch (Throwable $ err ) {
402415 throw new ExecutorException (ExecutorException::RUNTIME_FAILED , $ err ->getMessage (), null , $ err );
403416 }
@@ -511,6 +524,10 @@ public function createRuntime(
511524 $ message .= $ chunk ['content ' ];
512525 }
513526
527+ if ($ throwable instanceof ExecutorException) {
528+ throw new ExecutorException ($ throwable ->getType (), $ message , $ throwable ->getCode (), $ throwable );
529+ }
530+
514531 throw new \Exception ($ message , $ throwable ->getCode () ?: 500 , $ throwable );
515532 }
516533
@@ -545,14 +562,14 @@ private function getBuildCommands(string $command, string $version): array
545562 return [
546563 'sh ' ,
547564 '-c ' ,
548- 'touch /var/tmp/logs.txt && ( ' . $ command . ') >> /var/tmp/logs.txt 2>&1 && cat /var/tmp/logs.txt '
565+ 'touch /var/tmp/logs.txt && ( ' . $ command . ') >> /var/tmp/logs.txt 2>&1; status=$?; cat /var/tmp/logs.txt; if [ $status -ne 0 ]; then echo "Build command exited with code $status."; fi; exit $status '
549566 ];
550567 }
551568
552569 return [
553570 'bash ' ,
554571 '-c ' ,
555- 'mkdir -p /tmp/logging && touch /tmp/logging/timings.txt && touch /tmp/logging/logs.txt && script --log-out /tmp/logging/logs.txt --flush --log-timing /tmp/logging/timings.txt --return --quiet --command " ' . \str_replace ('" ' , '\" ' , $ command ) . '" '
572+ 'mkdir -p /tmp/logging && touch /tmp/logging/timings.txt && touch /tmp/logging/logs.txt && script --log-out /tmp/logging/logs.txt --flush --log-timing /tmp/logging/timings.txt --return --quiet --command " ' . \str_replace ('" ' , '\" ' , $ command ) . '"; status=$?; if [ $status -ne 0 ]; then echo "Build command exited with code $status."; fi; exit $status '
556573 ];
557574 }
558575
0 commit comments