Esempio n. 1
0
 private void handleException(Realm realm, StackOverflowError e) {
   // Create script exception with stacktrace from stackoverflow-error.
   ScriptException exception =
       newInternalError(realm.defaultContext(), Messages.Key.StackOverflow);
   exception.setStackTrace(e.getStackTrace());
   handleException(realm, exception);
 }
Esempio n. 2
0
 private void preConfigure() {
   // Jython sys.path
   String dataPackDirForwardSlashes = SCRIPT_FOLDER.getPath().replaceAll("\\\\", "/");
   String configScript = "import sys;sys.path.insert(0,'" + dataPackDirForwardSlashes + "');";
   try {
     this.eval("jython", configScript);
   } catch (ScriptException e) {
     _log.fatal("Failed preconfiguring jython: " + e.getMessage());
   }
 }
Esempio n. 3
0
 private void printScriptStackTrace(Realm realm, ScriptException e) {
   if (options.scriptStacktrace) {
     StringBuilder sb = new StringBuilder();
     printScriptFrames(sb, realm, e, 1);
     if (sb.length() == 0 && e.getCause() != null) {
       printScriptFrames(sb, realm, e.getCause(), 1);
     }
     console.writer().print(sb.toString());
   }
 }
Esempio n. 4
0
  public void reportScriptFileError(File script, ScriptException e) {
    String dir = script.getParent();
    String name = script.getName() + ".error.log";
    if (dir != null) {
      File file = new File(dir + "/" + name);
      FileOutputStream fos = null;
      try {
        if (!file.exists()) {
          file.createNewFile();
        }

        fos = new FileOutputStream(file);
        String errorHeader =
            "Error on: "
                + file.getCanonicalPath()
                + "\r\nLine: "
                + e.getLineNumber()
                + " - Column: "
                + e.getColumnNumber()
                + "\r\n\r\n";
        fos.write(errorHeader.getBytes());
        fos.write(e.getMessage().getBytes());
        _log.warn(
            "Failed executing script: "
                + script.getAbsolutePath()
                + ". See "
                + file.getName()
                + " for details.");
      } catch (IOException ioe) {
        _log.warn(
            "Failed executing script: "
                + script.getAbsolutePath()
                + "\r\n"
                + e.getMessage()
                + "Additionally failed when trying to write an error report on script directory. Reason: "
                + ioe.getMessage());
        ioe.printStackTrace();
      } finally {
        try {
          fos.close();
        } catch (Exception e1) {
        }
      }
    } else {
      _log.warn(
          "Failed executing script: "
              + script.getAbsolutePath()
              + "\r\n"
              + e.getMessage()
              + "Additionally failed when trying to write an error report on script directory.");
    }
  }
Esempio n. 5
0
 private void handleException(Realm realm, OutOfMemoryError e) {
   // Try to recover after OOM.
   Runtime rt = Runtime.getRuntime();
   long beforeGc = rt.freeMemory();
   rt.gc();
   long afterGc = rt.freeMemory();
   if (afterGc > beforeGc && (afterGc - beforeGc) < 50_000_000) {
     // Calling gc() cleared less than 50MB, assume unrecoverable OOM and rethrow error.
     throw e;
   }
   // Create script exception with stacktrace from oom-error.
   ScriptException exception =
       newInternalError(realm.defaultContext(), Messages.Key.OutOfMemoryVM);
   exception.setStackTrace(e.getStackTrace());
   handleException(realm, exception);
 }
Esempio n. 6
0
 private void handleException(Realm realm, ScriptException e) {
   String message = formatMessage("uncaught_exception", e.getMessage(realm.defaultContext()));
   console.printf("%s%n", message);
   printScriptStackTrace(realm, e);
   printStackTrace(e);
 }