55use Sentry \SentryBundle \Event \SentryUserContextEvent ;
66use Sentry \SentryBundle \SentrySymfonyEvents ;
77use Symfony \Component \Console \Event \ConsoleCommandEvent ;
8+ use Symfony \Component \Console \Event \ConsoleErrorEvent ;
9+ use Symfony \Component \Console \Event \ConsoleEvent ;
810use Symfony \Component \Console \Event \ConsoleExceptionEvent ;
911use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
1012use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
@@ -71,7 +73,7 @@ public function setClient(\Raven_Client $client)
7173 *
7274 * @param GetResponseEvent $event
7375 */
74- public function onKernelRequest (GetResponseEvent $ event )
76+ public function onKernelRequest (GetResponseEvent $ event ): void
7577 {
7678 if (HttpKernelInterface::MASTER_REQUEST !== $ event ->getRequestType ()) {
7779 return ;
@@ -94,7 +96,7 @@ public function onKernelRequest(GetResponseEvent $event)
9496 /**
9597 * @param GetResponseForExceptionEvent $event
9698 */
97- public function onKernelException (GetResponseForExceptionEvent $ event )
99+ public function onKernelException (GetResponseForExceptionEvent $ event ): void
98100 {
99101 $ exception = $ event ->getException ();
100102
@@ -114,18 +116,37 @@ public function onKernelException(GetResponseForExceptionEvent $event)
114116 *
115117 * @return void
116118 */
117- public function onConsoleCommand (ConsoleCommandEvent $ event )
119+ public function onConsoleCommand (ConsoleCommandEvent $ event ): void
118120 {
119121 // only triggers loading of client, does not need to do anything.
120122 }
121123
124+ public function onConsoleError (ConsoleErrorEvent $ event ): void
125+ {
126+ $ this ->handleConsoleError ($ event );
127+ }
128+
129+ public function onConsoleException (ConsoleExceptionEvent $ event ): void
130+ {
131+ $ this ->handleConsoleError ($ event );
132+ }
133+
122134 /**
123- * @param ConsoleExceptionEvent $event
135+ * @param ConsoleExceptionEvent|ConsoleErrorEvent $event
124136 */
125- public function onConsoleException ( ConsoleExceptionEvent $ event )
137+ private function handleConsoleError ( ConsoleEvent $ event ): void
126138 {
127139 $ command = $ event ->getCommand ();
128- $ exception = $ event ->getException ();
140+ switch (true ) {
141+ case $ event instanceof ConsoleErrorEvent:
142+ $ exception = $ event ->getError ();
143+ break ;
144+ case $ event instanceof ConsoleExceptionEvent:
145+ $ exception = $ event ->getException ();
146+ break ;
147+ default :
148+ throw new \InvalidArgumentException ('Event not recognized: ' . \get_class ($ event ));
149+ }
129150
130151 if ($ this ->shouldExceptionCaptureBeSkipped ($ exception )) {
131152 return ;
@@ -142,7 +163,7 @@ public function onConsoleException(ConsoleExceptionEvent $event)
142163 $ this ->client ->captureException ($ exception , $ data );
143164 }
144165
145- protected function shouldExceptionCaptureBeSkipped (\Exception $ exception )
166+ protected function shouldExceptionCaptureBeSkipped (\Throwable $ exception ): bool
146167 {
147168 foreach ($ this ->skipCapture as $ className ) {
148169 if ($ exception instanceof $ className ) {
@@ -171,7 +192,7 @@ private function setUserValue($user)
171192 }
172193
173194 if (is_object ($ user ) && method_exists ($ user , '__toString ' )) {
174- $ this ->client ->set_user_data ($ user -> __toString () );
195+ $ this ->client ->set_user_data (( string ) $ user );
175196 }
176197 }
177198}
0 commit comments