public static int extractErrorCode(String[] diagnostics) {
    int result = 0;
    Pattern errorCodeRegex = ErrorMsg.getErrorCodePattern();
    for (String mesg : diagnostics) {
      Matcher matcher = errorCodeRegex.matcher(mesg);
      if (matcher.find()) {
        result = Integer.parseInt(matcher.group(1));
        // We don't exit the loop early because we want to extract the error code
        // corresponding to the bottommost error coded exception.
      }
    }
    return result;
  }
JobDebugger takes a RunningJob that has failed and grabs the top 4 failing
tasks and outputs this information to the Hive CLI.
ql/src/java/org/apache/hadoop/hive/ql/exec/mr/JobDebugger.java