@@ -148,7 +148,8 @@ public void await() throws InterruptedException {
148
148
149
149
@ OnWebSocketError
150
150
public void onError (Session session , Throwable throwable ) {
151
-
151
+ // do nothing for now, this should at least repress "OnWebsocketError not registered" messages
152
+ runOnError ("Websocket error occurred with session " + session , throwable );
152
153
}
153
154
154
155
@ OnWebSocketClose
@@ -158,7 +159,7 @@ public void onClose(int statusCode, String reason) {
158
159
try {
159
160
this .onDisconnect .run (null );
160
161
} catch (Throwable t ) {
161
- t . printStackTrace ( );
162
+ runOnError ( "Could not close websocket connection" , t );
162
163
}
163
164
}
164
165
@@ -170,7 +171,7 @@ public void onConnect(Session session) {
170
171
fut = session .getRemote ().sendStringByFuture (new Gson ().toJson (new GetVersionRequest (this )));
171
172
fut .get (2 , TimeUnit .SECONDS );
172
173
} catch (Throwable t ) {
173
- t . printStackTrace ( );
174
+ runOnError ( "An error occurred while trying to get a session" , t );
174
175
}
175
176
}
176
177
@@ -182,7 +183,7 @@ public void onMessage(String msg) {
182
183
}
183
184
184
185
if (debug ) {
185
- log .debug (msg );
186
+ log .debug ("onMessage: " + msg );
186
187
}
187
188
188
189
try {
@@ -195,8 +196,6 @@ public void onMessage(String msg) {
195
196
try {
196
197
processIncomingResponse (responseBase , type );
197
198
} catch (Throwable t ) {
198
- log .error ("Failed to process response '" + type .getSimpleName () + "' from websocket." );
199
- t .printStackTrace ();
200
199
runOnError ("Failed to process response '" + type .getSimpleName () + "' from websocket" , t );
201
200
}
202
201
@@ -213,14 +212,10 @@ public void onMessage(String msg) {
213
212
try {
214
213
processIncomingEvent (msg , eventType );
215
214
} catch (Throwable t ) {
216
- log .error ("Failed to execute callback for event: " + eventType );
217
- t .printStackTrace ();
218
215
runOnError ("Failed to execute callback for event: " + eventType , t );
219
216
}
220
217
}
221
218
} catch (Throwable t ) {
222
- log .error ("Failed to process message from websocket." );
223
- t .printStackTrace ();
224
219
runOnError ("Failed to process message from websocket" , t );
225
220
}
226
221
}
@@ -264,8 +259,6 @@ private void processIncomingResponse(ResponseBase responseBase, Class type) {
264
259
try {
265
260
callbacks .get (type ).run (responseBase );
266
261
} catch (Throwable t ) {
267
- log .error ("Failed to execute callback for response: " + type );
268
- t .printStackTrace ();
269
262
runOnError ("Failed to execute callback for response: " + type , t );
270
263
}
271
264
}
@@ -330,7 +323,6 @@ private void processIncomingEvent(String msg, EventType eventType) {
330
323
331
324
private void authenticateWithServer (String challenge , String salt ) {
332
325
if (password == null ) {
333
- log .error ("Authentication required by server but no password set by client" );
334
326
runOnConnectionFailed ("Authentication required by server but no password set by client" );
335
327
return ;
336
328
}
@@ -352,8 +344,6 @@ private String generateAuthenticationResponseString(String challenge, String sal
352
344
try {
353
345
digest = MessageDigest .getInstance ("SHA-256" );
354
346
} catch (NoSuchAlgorithmException e ) {
355
- log .error ("Failed to perform password authentication with server" );
356
- e .printStackTrace ();
357
347
runOnConnectionFailed ("Failed to perform password authentication with server" );
358
348
return null ;
359
349
}
@@ -645,41 +635,44 @@ public void setStudioModeEnabled(boolean enabled, Callback callback) {
645
635
}
646
636
647
637
private void runOnError (String message , Throwable throwable ) {
638
+ log .debug ("Running onError with message: " + message + " and exception:" , throwable );
648
639
if (onError == null ) {
640
+ log .debug ("No onError callback was registered" );
649
641
return ;
650
642
}
651
643
652
644
try {
653
645
onError .run (message , throwable );
654
646
} catch (Throwable t ) {
655
- log .error ("Exception during callback execution for 'onError'" );
656
- t .printStackTrace ();
647
+ log .error ("Unable to run onError callback" , t );
657
648
}
658
649
}
659
650
660
651
private void runOnConnectionFailed (String message ) {
652
+ log .debug ("Running onConnectionFailed, with message: " + message );
661
653
if (onConnectionFailed == null ) {
654
+ log .debug ("No onConnectionFailed callback was registered" );
662
655
return ;
663
656
}
664
657
665
658
try {
666
659
onConnectionFailed .run (message );
667
660
} catch (Throwable t ) {
668
- log .error ("Exception during callback execution for 'onConnectionFailed'" );
669
- t .printStackTrace ();
661
+ log .error ("Unable to run OnConnectionFailed callback" , t );
670
662
}
671
663
}
672
664
673
665
private void runOnConnect (GetVersionResponse versionInfo ) {
666
+ log .debug ("Running onConnect with versionInfo: " + versionInfo );
674
667
if (onConnect == null ) {
668
+ log .debug ("No onConnect callback was registered" );
675
669
return ;
676
670
}
677
671
678
672
try {
679
673
onConnect .run (versionInfo );
680
674
} catch (Throwable t ) {
681
- log .error ("Exception during callback execution for 'onConnect'" );
682
- t .printStackTrace ();
675
+ log .error ("Unable to run OnConnect callback" , t );
683
676
}
684
677
}
685
678
}
0 commit comments