Permalink
Browse files

A bit of `try…catch` to make error-shutdown smooth

  • Loading branch information...
1 parent 1f07c06 commit b876cba4fb29da62f2cce52797c6e61640d492de @detro committed Nov 18, 2012
Showing with 24 additions and 19 deletions.
  1. +24 −19 src/main.js
View
43 src/main.js
@@ -53,29 +53,34 @@ phantom.injectJs("request_handlers/webelement_request_handler.js");
phantom.injectJs("request_handlers/router_request_handler.js");
phantom.injectJs("webelementlocator.js");
-// HTTP Request Router
-router = new ghostdriver.RouterReqHand();
+try {
+ // HTTP Request Router
+ router = new ghostdriver.RouterReqHand();
-// Check if parameters were given, regarding the "ip:port" to listen to
-if (ghostdriver.system.args[1]) {
- if (ghostdriver.system.args[1].indexOf(':') >= 0) {
- listenOn = ghostdriver.system.args[1].split(':');
- listenOnIp = listenOn[0];
- listenOnPort = listenOn[1];
- } else {
- listenOnPort = ghostdriver.system.args[1];
+ // Check if parameters were given, regarding the "ip:port" to listen to
+ if (ghostdriver.system.args[1]) {
+ if (ghostdriver.system.args[1].indexOf(':') >= 0) {
+ listenOn = ghostdriver.system.args[1].split(':');
+ listenOnIp = listenOn[0];
+ listenOnPort = listenOn[1];
+ } else {
+ listenOnPort = ghostdriver.system.args[1];
+ }
}
-}
-// Start the server
-if (server.listen(listenOnPort, router.handle)) {
- console.log('Ghost Driver running on port ' + server.port);
+ // Start the server
+ if (server.listen(listenOnPort, router.handle)) {
+ console.log('Ghost Driver running on port ' + server.port);
- // If parameters regarding a Selenium Grid HUB were given, register to it!
- if (ghostdriver.system.args[2]) {
- ghostdriver.hub.register(listenOnIp, listenOnPort, ghostdriver.system.args[2]);
+ // If parameters regarding a Selenium Grid HUB were given, register to it!
+ if (ghostdriver.system.args[2]) {
+ ghostdriver.hub.register(listenOnIp, listenOnPort, ghostdriver.system.args[2]);
+ }
+ } else {
+ throw new Error("ERROR: Could not start Ghost Driver");
+ phantom.exit(1);
}
-} else {
- console.error("ERROR: Could not start Ghost Driver");
+} catch (e) {
+ console.error(e);
phantom.exit(1);
}

0 comments on commit b876cba

Please sign in to comment.