diff --git a/src/main/java/io/krakens/grok/api/Grok.java b/src/main/java/io/krakens/grok/api/Grok.java index 6eb16ec..24d70f5 100644 --- a/src/main/java/io/krakens/grok/api/Grok.java +++ b/src/main/java/io/krakens/grok/api/Grok.java @@ -9,6 +9,7 @@ import java.util.regex.Pattern; import io.krakens.grok.api.Converter.IConverter; +import io.krakens.grok.api.exception.GrokException; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/io/krakens/grok/api/Match.java b/src/main/java/io/krakens/grok/api/Match.java index bb90f25..544ddd0 100644 --- a/src/main/java/io/krakens/grok/api/Match.java +++ b/src/main/java/io/krakens/grok/api/Match.java @@ -11,6 +11,7 @@ import java.util.regex.Matcher; import io.krakens.grok.api.Converter.IConverter; +import io.krakens.grok.api.exception.GrokException; /** * {@code Match} is a representation in {@code Grok} world of your log. @@ -84,12 +85,20 @@ public Map capture() { * * See also {@link #capture} which returns multiple values of the same key as list. * + * @return the matched elements + * @throws GrokException if a keys has multiple non-null values. */ - public Map captureFlattened() { + public Map captureFlattened() throws GrokException { return capture(true); } - private Map capture(boolean flattened ) { + /** + * Private implementation of captureFlattened and capture. + * @param will it flatten values. + * @return the matched elements. + * @throws GrokException if a keys has multiple non-null values, but only if flattened is set to true. + */ + private Map capture(boolean flattened ) throws GrokException { if (match == null) { return Collections.emptyMap(); } @@ -143,7 +152,7 @@ private Map capture(boolean flattened ) { capture.put(key, value); } if (currentValue != null && value != null) { - throw new RuntimeException( + throw new GrokException( format( "key '%s' has multiple non-null values, this is not allowed in flattened mode, values:'%s', '%s'", key,