-
Notifications
You must be signed in to change notification settings - Fork 910
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
Better rules parsing errors #708
Conversation
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'd like to see the lua files formatted right before trying to understand and test the new logic.
The cpp stuff looks good rn but I'll test it better once the lua formatting is done
return changed or changed_left or changed_right | ||
local status, changed_left = expand_macros(ast.left, defs, false) | ||
if status == false then | ||
return false, changed_left |
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'm not sure about the formatting of this one
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.
Do we have a lua formatter yet?
|
||
elseif ast.type == "UnaryBoolOp" then | ||
if (ast.argument.type == "Macro") then | ||
if (defs[ast.argument.value] == nil) then | ||
error("Undefined macro ".. ast.argument.value .. " used in filter.") | ||
return false, "Undefined macro ".. ast.argument.value .. " used in filter." |
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.
ditto
|
||
row, col = string.match(rules, pat) | ||
if row ~= nil and col ~= nil then | ||
rules = string.gsub(rules, pat, "") |
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.
again formatting here
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.
Except some formatting glitches (we'll fix soon in dedicated PR after having introduced lua coding style) it looks go to me
LGTM label has been added. Git tree hash: 4a23a0b60ca6b4d984c853c2dac11062ab4eef3b
|
New test options stdout_is/stderr_is do a direct comparison between stdout/stderr and the provided value. Test option validate_rules_file maps to -V arguments, which validate rules and exits. Signed-off-by: Mark Stemm <[email protected]>
When parsing rules files with -V (validate), print info on the result of loading the rules file to stdout. That way a caller can capture stdout to pass along any rules parsing error. Signed-off-by: Mark Stemm <[email protected]>
Instead of relying on lua errors to pass back parse errors, pass back an explicit true + required engine version or false + error message. Also clean up the error message to display info + context on the error. When the error related to yaml parsing, use the row number passed back in lyaml's error string to print the specific line with the error. When parsing rules/macros/lists, print the object being parsed alongside the error. Signed-off-by: Mark Stemm <[email protected]>
Add a bunch of additional test cases for validating rules files. Each has a specific kind of parse failure and checks for the appropriate error info on stdout. Signed-off-by: Mark Stemm <[email protected]>
27c8c70
to
9009372
Compare
LGTM label has been added. Git tree hash: 4f46d0e4761b438e14c8d56a94be06745def0618
|
@fntlnz , since we agreed that any lua formatting changes will occur in a separate PR, can you approve this one? I can't merge w/ requested changes. |
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.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fntlnz, leodido The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Thank you! |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area engine
/area rules
What this PR does / why we need it:
This cleans up rule validation to pass back consistent and appropriate error messages along with meaningful context. It can be used by callers that want to validate falco rules files.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: