}
protected void getErrorMessages(Iterator<TaskReport> reports, String type,
boolean errNotDbg, PigContext pigContext) throws Exception {
while(reports.hasNext()) {
TaskReport report = reports.next();
String msgs[] = report.getDiagnostics();
ArrayList<Exception> exceptions = new ArrayList<Exception>();
String exceptionCreateFailMsg = null;
boolean jobFailed = false;
if (msgs.length > 0) {
if (HadoopShims.isJobFailed(report)) {
jobFailed = true;
}
Set<String> errorMessageSet = new HashSet<String>();
for (int j = 0; j < msgs.length; j++) {
if (!errorMessageSet.contains(msgs[j])) {
errorMessageSet.add(msgs[j]);
if (errNotDbg) {
// errNotDbg is used only for failed jobs
// keep track of all the unique exceptions
try {
LogUtils.writeLog("Backend error message",
msgs[j], pigContext.getProperties()
.getProperty("pig.logfile"),
log);
Exception e = getExceptionFromString(msgs[j]);
exceptions.add(e);
} catch (Exception e1) {
exceptionCreateFailMsg = msgs[j];
}
} else {
log.debug("Error message from task (" + type + ") "
+ report.getTaskID() + msgs[j]);
}
}
}
}
// if there are no valid exception that could be created, report
if (jobFailed && (exceptions.size() == 0) && (exceptionCreateFailMsg != null)) {
int errCode = 2997;
String msg = "Unable to recreate exception from backed error: "
+ exceptionCreateFailMsg;
throw new ExecException(msg, errCode, PigException.BUG);
}
// if its a failed job then check if there is more than one
// exception
// more than one exception implies possibly different kinds of
// failures
// log all the different failures and throw the exception
// corresponding
// to the first failure
if (jobFailed) {
if (exceptions.size() > 1) {
for (int j = 0; j < exceptions.size(); ++j) {
String headerMessage = "Error message from task ("
+ type + ") " + report.getTaskID();
LogUtils.writeLog(exceptions.get(j), pigContext
.getProperties().getProperty("pig.logfile"),
log, false, headerMessage, false, false);
}
throw exceptions.get(0);