if (cause instanceof PySyntaxError) {
// set a clear syntax error message
PySyntaxError syntaxError = (PySyntaxError) cause;
try {
PyString fileName, text;
PyInteger lineNumber, columnNumber;
if (syntaxError.value instanceof PyTuple) {
PyObject[] infos = ((PyTuple) ((PyTuple) syntaxError.value).getArray()[1]).getArray();
fileName = (PyString) infos[0];
lineNumber = (PyInteger) infos[1];
columnNumber = (PyInteger) infos[2];
text = (PyString) infos[3];
} else {
fileName = (PyString) syntaxError.value.__getattr__(new PyString("filename"));
lineNumber = (PyInteger) syntaxError.value.__getattr__(new PyString("lineno"));
columnNumber = (PyInteger) syntaxError.value.__getattr__(new PyString("offset"));
text = (PyString) syntaxError.value.__getattr__(new PyString("text"));
message = "Python syntax error in file " + fileName + " at line " + lineNumber + ", column " + columnNumber + ":\n" + text;
}
message = "Python syntax error in file " + fileName + " at line " + lineNumber + ", column " + columnNumber + ":\n" + text;
result.addStackTraceElement(new StackTraceElement("", "", fileName.toString(), Integer.parseInt(lineNumber.toString())));
dumpStack = false;
} catch (PyException pye) {
message = "Python syntax error (Couldn't decode localization of error)";
}
} else if (cause instanceof PyException) {
PyException pe = (PyException) cause;
if (pe.value instanceof PyJavaInstance) {
// check if exception is UndeclaredThrowableException
// in this case status is "failed" and message is taken from cause exception
Object javaError = pe.value.__tojava__(Throwable.class);
if (javaError != null && javaError != Py.NoConversion) {
if (javaError instanceof QTasteException) {
handleQTasteException((QTasteException) javaError, result);
message = result.getExtraResultDetails();
} else if (javaError instanceof UndeclaredThrowableException) {
result.setStatus(TestResult.Status.FAIL);
Throwable undeclaredThrowable = ((UndeclaredThrowableException) javaError).getCause();
if (undeclaredThrowable instanceof InvocationTargetException) {
message = getThrowableDescription(((InvocationTargetException) undeclaredThrowable).getCause());
} else {
message = getThrowableDescription(undeclaredThrowable);
}
} else if (javaError instanceof Throwable) {
message = getThrowableDescription((Throwable) javaError);
}
}
}
if (message == null) {
if (pe.type instanceof PyClass) {
String errorName = null, errorValue;
try {
PyObject doc = pe.value.__getattr__(new PyString("__doc__"));
if (doc != Py.None) {
errorName = doc.toString();
if (errorName.endsWith(".")) {
errorName = errorName.substring(0, errorName.length() - 1);
}