This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
add parse error handler for precompute args failures #93
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/org/graylog/plugins/pipelineprocessor/ast/exceptions/PrecomputeFailure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.ast.exceptions; | ||
|
||
public class PrecomputeFailure extends RuntimeException { | ||
private final String argumentName; | ||
|
||
public PrecomputeFailure(String argumentName, Exception cause) { | ||
super(cause); | ||
this.argumentName = argumentName; | ||
} | ||
|
||
public String getArgumentName() { | ||
return argumentName; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return "Unable to pre-compute argument " + getArgumentName() + ": " + getCause().getMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ain/java/org/graylog/plugins/pipelineprocessor/parser/errors/InvalidFunctionArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* This file is part of Graylog Pipeline Processor. | ||
* | ||
* Graylog Pipeline Processor is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog Pipeline Processor is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog Pipeline Processor. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog.plugins.pipelineprocessor.parser.errors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.graylog.plugins.pipelineprocessor.ast.exceptions.PrecomputeFailure; | ||
import org.graylog.plugins.pipelineprocessor.ast.functions.Function; | ||
import org.graylog.plugins.pipelineprocessor.ast.functions.ParameterDescriptor; | ||
import org.graylog.plugins.pipelineprocessor.parser.RuleLangParser; | ||
|
||
public class InvalidFunctionArgument extends ParseError { | ||
private final Function<?> function; | ||
private final PrecomputeFailure failure; | ||
|
||
public InvalidFunctionArgument(RuleLangParser.FunctionCallContext ctx, | ||
Function<?> function, | ||
PrecomputeFailure failure) { | ||
super("invalid_function_argument", ctx); | ||
this.function = function; | ||
this.failure = failure; | ||
} | ||
|
||
@JsonProperty("reason") | ||
@Override | ||
public String toString() { | ||
int paramPosition = 1; | ||
for (ParameterDescriptor descriptor : function.descriptor().params()) { | ||
if (descriptor.name().equals(failure.getArgumentName())) { | ||
break; | ||
} | ||
paramPosition++; | ||
} | ||
|
||
return "Unable to pre-compute value for " + paramPosition + ". argument " + failure.getArgumentName() + " in call to function " + function.descriptor().name() + ": " + failure.getCause().getMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/test/resources/org/graylog/plugins/pipelineprocessor/parser/invalidArgumentValue.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rule "invalid arg" | ||
when now_in_tz("123") // this isn't a valid tz | ||
then | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is should be "," before argument,right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there should be "st", "nd", "rd", "th" there, but I was too lazy for an error message ;)
It's the argument position, since we don't highlight it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe write:
return "Unable to pre-compute value for argument " + failure.getArgumentName() + " (pos. "+paramPosition +") in call..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I like the abbreviated ordinal better, so I got unlazy and implemented that. The error now reads:
Unable to pre-compute value for 1st argument timezone in call to function now_in_tz: The datetime zone id '123' is not recognised
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 👍
Maybe put argument name in quotes for better readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now I'll skip that, because then I would need to touch all the other errors, too.
We also don't know how we will continue with the editor in 2.2 so I'd like to leave it at this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Anyway 3rd much better than 3. :)