You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by de...@apache.org on 2016/09/09 20:50:17 UTC
incubator-systemml git commit: [SYSTEMML-901] Improve unavailable
MLContext message
Repository: incubator-systemml
Updated Branches:
refs/heads/master 7fa318674 -> 63e2060fe
[SYSTEMML-901] Improve unavailable MLContext message
Add option to suppress MLContextException stacktrace.
Closes #238.
Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/63e2060f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/63e2060f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/63e2060f
Branch: refs/heads/master
Commit: 63e2060fe27a4f59531f38f0283f0a823eacad7a
Parents: 7fa3186
Author: Deron Eriksson <de...@us.ibm.com>
Authored: Fri Sep 9 13:46:51 2016 -0700
Committer: Deron Eriksson <de...@us.ibm.com>
Committed: Fri Sep 9 13:46:51 2016 -0700
----------------------------------------------------------------------
.../org/apache/sysml/api/MLContextProxy.java | 6 ++--
.../sysml/api/mlcontext/MLContextException.java | 29 ++++++++++++++++++--
2 files changed, 30 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/63e2060f/src/main/java/org/apache/sysml/api/MLContextProxy.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/MLContextProxy.java b/src/main/java/org/apache/sysml/api/MLContextProxy.java
index f8f31d6..8002266 100644
--- a/src/main/java/org/apache/sysml/api/MLContextProxy.java
+++ b/src/main/java/org/apache/sysml/api/MLContextProxy.java
@@ -21,6 +21,7 @@ package org.apache.sysml.api;
import java.util.ArrayList;
+import org.apache.sysml.api.mlcontext.MLContextException;
import org.apache.sysml.api.monitoring.Location;
import org.apache.sysml.parser.Expression;
import org.apache.sysml.parser.LanguageException;
@@ -90,10 +91,9 @@ public class MLContextProxy
return org.apache.sysml.api.MLContext.getActiveMLContext();
} else if (org.apache.sysml.api.mlcontext.MLContext.getActiveMLContext() != null) {
return org.apache.sysml.api.mlcontext.MLContext.getActiveMLContext();
- } else {
- return null;
}
-
+ throw new MLContextException("No MLContext object is currently active. Have you created one? "
+ + "Hint: in Scala, 'val ml = new MLContext(sc)'", true);
}
public static void setInstructionForMonitoring(Instruction inst) {
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/63e2060f/src/main/java/org/apache/sysml/api/mlcontext/MLContextException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MLContextException.java b/src/main/java/org/apache/sysml/api/mlcontext/MLContextException.java
index 63e6b64..ca98a89 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/MLContextException.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/MLContextException.java
@@ -21,12 +21,13 @@ package org.apache.sysml.api.mlcontext;
/**
* Uncaught exception representing SystemML exceptions that occur through the
- * MLContext API
+ * MLContext API.
*
*/
public class MLContextException extends RuntimeException {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1842275827863526536L;
+ private boolean suppressStacktrace = false;
public MLContextException() {
super();
@@ -44,4 +45,28 @@ public class MLContextException extends RuntimeException {
super(cause);
}
+ /**
+ * Generate an exception and optionally suppress the stacktrace. This can be
+ * useful in an environment such as a Spark Shell in certain situations
+ * where a stacktrace may be extraneous.
+ *
+ * @param message
+ * the exception message
+ * @param suppressStacktrace
+ * {@code true} to suppress stacktrace, {@code false} otherwise
+ */
+ public MLContextException(String message, boolean suppressStacktrace) {
+ super(message, null, suppressStacktrace, !suppressStacktrace);
+ this.suppressStacktrace = suppressStacktrace;
+ }
+
+ @Override
+ public String toString() {
+ if (suppressStacktrace) {
+ return getLocalizedMessage();
+ } else {
+ return super.toString();
+ }
+ }
+
}