"use strict";

var system = UIATarget.localTarget().host();
// clientPath is relative to where you run the appium server from
var clientPath = 'instruments/client.js';

var sendResultAndGetNext = function(result) {
  var args = [clientPath, '-s', '/tmp/instruments_sock'];
  if (typeof result !== "undefined") {
    args = args.concat(['-r', JSON.stringify(result)]);
  }
  var res = system.performTaskWithPathArgumentsTimeout('/usr/local/bin/node', args, 20);
  if (res.exitCode !== 0) {
    console.log("Error talking with instruments client, here's stderr:");
    console.log(res.stderr);
  }
  return res.stdout;
};

var getFirstCommand = function() {
  return sendResultAndGetNext();
};

@@ -365,16 +365,26 @@
 %5D);%0A  %7D%0A
+  try %7B%0A  
   var re
@@ -463,13 +463,136 @@
 gs, 
-2
+3
 0);%0A
+  %7D catch(e) %7B%0A    console.log(%22Socket timed out waiting for a new command, why wasn't there one?%22);%0A    return null;%0A  %7D%0A%0A
   if

add better log information about what it means when there's a socket timeout