@@ -527,58 +527,48 @@ protected Response execute(CommandPayload payload) {
527527 // Unwrap the response value by converting any JSON objects of the form
528528 // {"ELEMENT": id} to RemoteWebElements.
529529 Object value = getElementConverter ().apply (response .getValue ());
530- if (value instanceof WebDriverException ) {
531- ((WebDriverException ) value ).addInfo ("Command" , command .toString ());
532- }
533530 response .setValue (value );
534531 } catch (Throwable e ) {
535532 log (sessionId , command .getName (), command , When .EXCEPTION );
533+ WebDriverException toThrow ;
536534 if (command .getName ().equals (DriverCommand .NEW_SESSION )) {
537- throw new SessionNotCreatedException (
538- "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." ,
535+ toThrow = new SessionNotCreatedException (
536+ "Could not start a new session. Possible causes are invalid address"
537+ + " of the remote server or browser start-up failure." ,
539538 e );
539+ } else if (e instanceof WebDriverException ) {
540+ toThrow = (WebDriverException ) e ;
540541 } else {
541- WebDriverException toThrow =
542- e instanceof WebDriverException
543- ? (WebDriverException ) e
544- : new UnreachableBrowserException (
545- "Error communicating with the remote browser. It may have died." , e );
546- toThrow .addInfo ("Command" , command .toString ());
547- if (getSessionId () != null ) {
548- toThrow .addInfo (WebDriverException .SESSION_ID , getSessionId ().toString ());
549- }
550- if (getCapabilities () != null ) {
551- toThrow .addInfo ("Capabilities" , getCapabilities ().toString ());
552- }
553- throw toThrow ;
542+ toThrow = new UnreachableBrowserException (
543+ "Error communicating with the remote browser. It may have died." , e );
554544 }
545+ populateWebDriverException (toThrow );
546+ toThrow .addInfo ("Command" , command .toString ());
547+ throw toThrow ;
555548 } finally {
556549 Thread .currentThread ().setName (currentName );
557550 }
558551
559552 try {
560553 errorHandler .throwIfResponseFailed (response , System .currentTimeMillis () - start );
561554 } catch (WebDriverException ex ) {
562- if (command .getParameters () != null && command .getParameters ().containsKey ("using" ) && command .getParameters ().containsKey ("value" )) {
563- ex .addInfo (
564- "*** Element info" ,
565- String .format (
566- "{Using=%s, value=%s}" ,
567- command .getParameters ().get ("using" ),
568- command .getParameters ().get ("value" )));
569- }
570- ex .addInfo (WebDriverException .DRIVER_INFO , this .getClass ().getName ());
571- if (getSessionId () != null ) {
572- ex .addInfo (WebDriverException .SESSION_ID , getSessionId ().toString ());
573- }
574- if (getCapabilities () != null ) {
575- ex .addInfo ("Capabilities" , getCapabilities ().toString ());
576- }
555+ populateWebDriverException (ex );
556+ ex .addInfo ("Command" , command .toString ());
577557 throw ex ;
578558 }
579559 return response ;
580560 }
581561
562+ private void populateWebDriverException (WebDriverException ex ) {
563+ ex .addInfo (WebDriverException .DRIVER_INFO , this .getClass ().getName ());
564+ if (getSessionId () != null ) {
565+ ex .addInfo (WebDriverException .SESSION_ID , getSessionId ().toString ());
566+ }
567+ if (getCapabilities () != null ) {
568+ ex .addInfo ("Capabilities" , getCapabilities ().toString ());
569+ }
570+ }
571+
582572 protected Response execute (String driverCommand , Map <String , ?> parameters ) {
583573 return execute (new CommandPayload (driverCommand , parameters ));
584574 }
0 commit comments