You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/09/24 07:58:06 UTC
[2/2] git commit: ISIS-540: Exception Recognizer for
JDODataStoreException now does *not* recognise...
ISIS-540: Exception Recognizer for JDODataStoreException now does *not* recognise...
.. certain phrases that would likely constitute an error in the system that should be surfaced to the dev team, ie not swallowed in a friendly error message
* "NOT NULL check constraint" -- eg a mandatory property has most likely not been set.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/9e550a98
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/9e550a98
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/9e550a98
Branch: refs/heads/master
Commit: 9e550a98f8698259167732466681fb7a8521e5b6
Parents: beb614a
Author: Dan Haywood <da...@apache.org>
Authored: Tue Sep 24 06:57:50 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Tue Sep 24 06:57:50 2013 +0100
----------------------------------------------------------------------
...ptionRecognizerForJDODataStoreException.java | 2 +-
.../exceprecog/ExceptionRecognizerForType.java | 41 +++++++++++++++++++-
2 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/9e550a98/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
index 94d9381..a79e090 100644
--- a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
+++ b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
@@ -23,7 +23,7 @@ import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
public class ExceptionRecognizerForJDODataStoreException extends ExceptionRecognizerForType {
public ExceptionRecognizerForJDODataStoreException() {
- super(javax.jdo.JDODataStoreException.class,
+ super(ofTypeExcluding(javax.jdo.JDODataStoreException.class, "NOT NULL check constraint"),
prefix("Unable to save changes. " +
"Does similar data already exist, or has referenced data been deleted?"));
}
http://git-wip-us.apache.org/repos/asf/isis/blob/9e550a98/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
index 7a3e74b..76760a3 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
@@ -18,8 +18,11 @@
*/
package org.apache.isis.applib.services.exceprecog;
+import java.util.List;
+
import com.google.common.base.Function;
import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import org.apache.isis.applib.annotation.Hidden;
@@ -37,7 +40,11 @@ import org.apache.isis.applib.annotation.Hidden;
@Hidden
public class ExceptionRecognizerForType extends ExceptionRecognizerDelegating {
- private final static Predicate<Throwable> ofType(final Class<? extends Throwable> exceptionType) {
+ protected final static Predicate<Throwable> ofTypeExcluding(final Class<? extends Throwable> exceptionType, final String... messages) {
+ return Predicates.and(ofType(exceptionType), excluding(messages));
+ }
+
+ protected final static Predicate<Throwable> ofType(final Class<? extends Throwable> exceptionType) {
return new Predicate<Throwable>() {
@Override
public boolean apply(Throwable input) {
@@ -45,9 +52,39 @@ public class ExceptionRecognizerForType extends ExceptionRecognizerDelegating {
}
};
}
+
+ /**
+ * A {@link Predicate} that {@link Predicate#apply(Object) applies} only if the message(s)
+ * supplied do <i>NOT</i> appear in the {@link Throwable} or any of its {@link Throwable#getCause() cause}s
+ * (recursively).
+ *
+ * <p>
+ * Intended to prevent too eager matching of an overly general exception type.
+ */
+ protected final static Predicate<Throwable> excluding(final String... messages) {
+ return new Predicate<Throwable>() {
+ @Override
+ public boolean apply(Throwable input) {
+ final List<Throwable> causalChain = Throwables.getCausalChain(input);
+ for (String message : messages) {
+ for (Throwable throwable : causalChain) {
+ final String throwableMessage = throwable.getMessage();
+ if(throwableMessage != null && throwableMessage.contains(message)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ };
+ }
public ExceptionRecognizerForType(final Class<? extends Exception> exceptionType, final Function<String,String> messageParser) {
- super(new ExceptionRecognizerGeneral(ofType(exceptionType), messageParser));
+ this(ofType(exceptionType), messageParser);
+ }
+
+ public ExceptionRecognizerForType(final Predicate<Throwable> predicate, final Function<String,String> messageParser) {
+ super(new ExceptionRecognizerGeneral(predicate, messageParser));
}
public ExceptionRecognizerForType(Class<? extends Exception> exceptionType) {