Skip to content
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

Unable to use "divided_by" in Event Formatting Agent #2188

Closed
stesie opened this issue Jan 4, 2018 · 1 comment · Fixed by #2189
Closed

Unable to use "divided_by" in Event Formatting Agent #2188

stesie opened this issue Jan 4, 2018 · 1 comment · Fixed by #2189

Comments

@stesie
Copy link
Contributor

stesie commented Jan 4, 2018

This relates to #2021, yet wasn't really tracked down back then, hence once more with more details:

Event Formatting Agent options:

{
  "instructions": {
    "message": "{{ 23 | divided_by: content.some_value }}"
  },
  "matchers": [],
  "mode": "clean"
}

... give it whatever name and click "dry run". ("save" also fails for same reasons, see below)

Sample event:

{
  "content": {
    "some_value": "23"
  }
}

Obviously the result should be 1 (23 divided by 23), yet it never is evaluated at all.

Problem is that LiquidInterpolatable#validate_interpolation tries to interpolate the template (probably to check for syntax errors in liquid template). Yet since there is no event data during validation it tries to divide by zero, which fails for obvious reasons. That way validation however fails, so the agent is neither saved nor is dry-run performed.

I'm not sure what a good resolution might look like, since template validation makes sense. Probably to just catch the error in the current vaildate_interpolation function and ignore it, like so:

--- app/concerns/liquid_interpolatable.rb       2018-01-04 19:25:04.373951061 +0100
+++ /home/stesie/liquid_interpolatable.rb       2018-01-04 19:16:49.000000000 +0100
@@ -15,6 +15,8 @@
 
   def validate_interpolation
     interpolated
+  rescue Liquid::ZeroDivisionError => e
+    # ignore error (due to possibly missing variables)
   rescue Liquid::Error => e
     errors.add(:options, "has an error with Liquid templating: #{e.message}")
   rescue
@dsander
Copy link
Collaborator

dsander commented Jan 5, 2018

Thanks for the detailed explanation. Rescueing the ZeroDvisionError sounds like a good solution to me, do you mind opening a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants