static FlinkException createAndLogException(PyException pe, Logger log) { StringWriter sw = new StringWriter(); try (PrintWriter pw = new PrintWriter(sw)) { pe.printStackTrace(pw); } String pythonStackTrace = sw.toString().trim(); log.error("Python function failed: " + System.lineSeparator() + pythonStackTrace); return new FlinkException("Python function failed: " + pythonStackTrace); } }
public synchronized String toString() { ByteArrayOutputStream buf = new ByteArrayOutputStream(); if (!printingStackTrace) { printStackTrace(new PrintStream(buf)); } return buf.toString(); }
/** * Compiles the python file <code>src</code> to bytecode filling in <code>moduleName</code> as * its name, and stores it in <code>compiled</code>. This is called by process for every file * that's compiled, so subclasses can override this method to affect or track the compilation. */ protected void compile(File src, File compiled, String moduleName) { byte[] bytes; try { bytes = imp.compileSource(moduleName, src); } catch (PyException pye) { pye.printStackTrace(); throw new BuildException("Compile failed; see the compiler error output for details."); } File dir = compiled.getParentFile(); if (!dir.exists() && !compiled.getParentFile().mkdirs()) { throw new BuildException("Unable to make directory for compiled file: " + compiled); } imp.cacheCompiledSource(src.getAbsolutePath(), compiled.getAbsolutePath(), bytes); }
pe.printStackTrace(); // Print the Jython-native stack trace log.error("Exception encountered in Python code", pe); return -1;