@@ -81,8 +81,9 @@ public function sendCustomControl(ServiceIdentificator $serviceId, int $control)
8181 $ result = win32_send_custom_control ($ serviceId ->serviceId (), $ serviceId ->machine (), $ control );
8282 } catch (\Win32ServiceException $ e ) {
8383 $ result = $ e ->getCode ();
84+ $ errorMessage = $ e ->getMessage ();
8485 }
85- $ this ->checkResponseAndConvertInExceptionIfNeed ($ result , $ serviceId );
86+ $ this ->checkResponseAndConvertInExceptionIfNeed ($ result , $ serviceId, $ errorMessage ?? '' );
8687 $ this ->throwExceptionIfError (
8788 $ result ,
8889 Win32ServiceException::class,
@@ -111,19 +112,24 @@ private function actionForService(ServiceIdentificator $serviceId, string $actio
111112 throw new InvalidServiceStatusException (sprintf ('The service is not %s ' , $ check ));
112113 }
113114
114- $ result = match ($ action ) {
115- 'start ' => win32_start_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
116- 'stop ' => win32_stop_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
117- 'pause ' => win32_pause_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
118- 'continue ' => win32_continue_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
119- default => throw new ServiceStateActionException (sprintf ('Action "%s" for service is unknown ' , $ action )),
120- };
115+ try {
116+ $ result = match ($ action ) {
117+ 'start ' => win32_start_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
118+ 'stop ' => win32_stop_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
119+ 'pause ' => win32_pause_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
120+ 'continue ' => win32_continue_service ($ serviceId ->serviceId (), $ serviceId ->machine ()),
121+ default => throw new ServiceStateActionException (sprintf ('Action "%s" for service is unknown ' , $ action )),
122+ };
123+ } catch (\Win32ServiceException $ e ) {
124+ $ result = $ e ->getCode ();
125+ $ errorMessage = $ e ->getMessage ();
126+ }
121127
122- $ this ->checkResponseAndConvertInExceptionIfNeed ($ result , $ serviceId );
128+ $ this ->checkResponseAndConvertInExceptionIfNeed ($ result , $ serviceId, $ errorMessage ?? null );
123129 $ this ->throwExceptionIfError (
124130 $ result ,
125131 ServiceStateActionException::class,
126- sprintf ('Unable to %s service ' , $ action )
132+ sprintf ('Unable to %s service. %s ' , $ action, $ errorMessage ?? '' )
127133 );
128134 }
129135}
0 commit comments