Skip to content

Match.capture nows throws a GrokException #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/io/krakens/grok/api/Grok.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 12 additions & 3 deletions src/main/java/io/krakens/grok/api/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -84,12 +85,20 @@ public Map<String, Object> 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<String, Object> captureFlattened() {
public Map<String, Object> captureFlattened() throws GrokException {
return capture(true);
}

private Map<String, Object> 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<String, Object> capture(boolean flattened ) throws GrokException {
if (match == null) {
return Collections.emptyMap();
}
Expand Down Expand Up @@ -143,7 +152,7 @@ private Map<String, Object> 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,
Expand Down