private static List<? extends StaticError> flattenErrors(StaticError ex) { List<StaticError> result = new LinkedList<StaticError>(); if (ex instanceof MultipleStaticError) { for (StaticError err : (MultipleStaticError) ex) result.addAll(flattenErrors(err)); } else result.add(new WrappedException(ex, Debug.stackTraceOn())); return result; }
/** * @param out * @param path * @param file_name * @param doLink * @return * @throws UserError * @throws IOException */ private static int compileWithErrorHandling(String s, Option<String> out, boolean doLink) throws UserError, IOException { int return_code = 0; try { APIName name = NodeUtil.apiName(s); Path path = sourcePath(s, name); String file_name = name.toString() + (s.endsWith(".fss") ? ".fss" : ".fsi"); List<StaticError> errors = new ArrayList<StaticError>(); for (StaticError error : IterUtil.sort(compilerPhases(path, file_name, out, doLink), StaticError.comparator)) { if (!error.toString().equals("")) errors.add(error); } return_code = reportErrors(errors, file_name); } catch (StaticError e) { return_code = reportErrors(flattenErrors(e), new File(s).getName()); } catch (ProgramError e) { System.err.println(e.getMessage()); e.printInterpreterStackTrace(System.err); if (Debug.stackTraceOn()) { e.printStackTrace(); } else { System.err.println(turnOnDebugMessage); } return_code = 1; } return return_code; }