Add a simple extended error message (#4646) by christianbender · Pull Request #5568 · processing/processing
String[] sourceFiles = Util.listFiles(build.getSrcFolder(), false, ".java"); String[] command = PApplet.concat(baseCommand, sourceFiles); //PApplet.println(command);
try { // Load errors into a local StringBuilder
try { Class<?> batchClass = Class.forName("org.eclipse.jdt.core.compiler.batch.BatchCompiler", false, loader);
} catch (Exception e) { e.printStackTrace(); throw new SketchException("Unknown error inside the compiler.");
BufferedReader reader = new BufferedReader(new StringReader(errorBuffer.toString())); //System.err.println(errorBuffer.toString());
String line = null; while ((line = reader.readLine()) != null) { //System.out.println("got line " + line); // debug
// get first line, which contains file name, line number, // and at least the first line of the error message String errorFormat = "([\\w\\d_]+.java):(\\d+):\\s*(.*):\\s*(.*)\\s*"; String[] pieces = PApplet.match(line, errorFormat); //PApplet.println(pieces);
// if it's something unexpected, die and print the mess to the console if (pieces == null) {
// extended error message or certain error message
if (!errorMessage.matches("([\\w\\d_]+.java):(\\d+):\\s*(.*):\\s*(.*)\\s*")) { switch (errorMessage) { case "23)": // cast error: int -> boolean errorMessage = "int constant cannot be casted into boolean"; break; default: errorMessage = pieces[3] + " " + errorMessage; break; } }
exception = build.placeException(errorMessage, dotJavaFilename, dotJavaLineIndex);
if (exception == null) { exception = new SketchException(errorMessage);
} else if (errorMessage.endsWith("cannot be resolved")) { // xxx cannot be resolved //println(xxx);
String what = errorMessage.substring(0, errorMessage.indexOf(' '));
if (what.equals("LINE_LOOP") ||
// System.out.printf("DEBUG: class Compiler -- end of first try -- compile(...) exception=%s\n",exception); // DEBUG } catch (IOException e) { String bigSigh = "Error while compiling. (" + e.getMessage() + ")"; exception = new SketchException(bigSigh);
// System.out.printf("DEBUG: class Compiler -- END of compile(...)\n"); // DEBUG
return success; }