yesworkflow-org / yw-prototypes

Research prototype with tutorial. Start here to learn about and try YesWorkflow.
http://yesworkflow.org/wiki
Other
33 stars 13 forks source link

Graceful failure for @LOG that follows @IN #43

Open chicoreus opened 7 years ago

chicoreus commented 7 years ago

Naïve use of @LOG would simply embedd it in an @BEGIN @END block where a logging statement occurs, however, @LOG appears to need to follow an @OUT annotation, having a bare @LOG which happens to follow a @IN statement results in a not immediately helpful exception:

java.lang.ClassCastException: org.yesworkflow.annotations.In cannot be cast to org.yesworkflow.annotations.Out

Graceful failure in this case with a pertinent error message would help.

To reproduce:

# @BEGIN FilterExcludingMarine 
# @IN TaggedDataRecord         
# @LOG {timestamp} [{loglevel}] ACTOR<{actorname}> ->  [{filterKey}]=[{matchValue}]:{match}. Passing occurrenceID={occurrenceID}    
# @OUT NotMarine
# @END FilterExcludingMarin
chicoreus commented 7 years ago

Here's a potential fix:

diff --git a/src/main/java/org/yesworkflow/extract/DefaultExtractor.java b/src/main/java/org/yesworkflow/extract/DefaultExtractor.java
index 5e25c66..3bb96c9 100644
--- a/src/main/java/org/yesworkflow/extract/DefaultExtractor.java
+++ b/src/main/java/org/yesworkflow/extract/DefaultExtractor.java
@@ -319,7 +319,11 @@ public class DefaultExtractor implements Extractor {
                                     break;
                     case IN:        annotation = new In(id, sourceId, lineNumber, annotationString);
                                     break;
-                    case LOG:       annotation = new Log(id, sourceId, lineNumber, annotationString, (Out) primaryAnnotation);
+                    case LOG:       try { 
+                                        annotation = new Log(id, sourceId, lineNumber, annotationString, (Out) primaryAnnotation);
+                                    } catch (ClassCastException cce) { 
+                                        throw new YWMarkupException("A LOG annotation must follow an OUT annotation as its primaryAnnotation.");
+                                    }
                                     break;
                     case OUT:       annotation = new Out(id, sourceId, lineNumber, annotationString);
                                     break;