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

rethrow script compilation exceptions into ingest configuration exceptions #19318

Merged
merged 2 commits into from
Jul 20, 2016

Conversation

talevy
Copy link
Contributor

@talevy talevy commented Jul 7, 2016

Currently, mustache compile exceptions in pipelines are reported as regular ES exceptions, e.g.

{
  "error": {
    "root_cause": [
      {
        "type": "general_script_exception",
        "reason": "Failed to compile inline script [{{#join}}{{/join}}] using lang [mustache]"
      }
    ],
    "type": "general_script_exception",
    "reason": "Failed to compile inline script [{{#join}}{{/join}}] using lang [mustache]",
    "caused_by": {
      "type": "mustache_exception",
      "reason": "Mustache function [join] must contain one and only one identifier"
    }
  },
  "status": 500
}

This makes it difficult to gather which property in the pipeline configuration is causing this exception. This PR wraps these exceptions in ElasticsearchParseException so that we can relay the information

@talevy talevy added >bug :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v5.0.0-alpha5 labels Jul 7, 2016
return templateService.compile(propertyValue);
} catch (Exception e) {
throw ConfigurationUtils.newConfigurationException(processorType, processorTag, propertyName, e.getMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lose the original exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't lose the original exception. It's already difficult enough to debug script exceptions without them being swallowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thought I could re-use some headers configuration stuff and enough information would make its way through the current exception's message

@talevy talevy force-pushed the rethrow-template-compile branch 2 times, most recently from def1617 to 5c6bbef Compare July 7, 2016 23:48
@talevy
Copy link
Contributor Author

talevy commented Jul 7, 2016

@rmuir @jdconrad updated the ElasticsearchParseException to carry the original cause with it. thanks!

@martijnvg
Copy link
Member

LGTM

String propertyValue, TemplateService templateService) {
try {
return templateService.compile(propertyValue);
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this code path correctly, this converts every exception thrown during template compilation into an ElasticsearchParseException and I'm not comfortable with that. For example, it means bugs in compilation get converted into a parse exception that sounds like the user can correct? What's the reasoning here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've been using ElasticsearchParseException as the exception container for all our pipeline build-time configuration exceptions.

it means bugs in compilation get converted into a parse exception that sounds like the user can correct

why would the user not be able to correct these exceptions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would the user not be able to correct these exceptions?

Because I'm specifically referring to exceptions being thrown because of bugs in the compilation explicitly not due to the user's template.

Copy link
Contributor Author

@talevy talevy Jul 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I guess I am not familiar with such exceptions. If all such exceptions extend ElasticsearchException then I suppose there is no real need to wrap the exception, but instead just add the appropriate ingest headers. So, I can check for whether an ElasticsearchException is thrown and simply add the headers and pass it along. If other exceptions are thrown, I would need to wrap it in some sort of ElasticsearchException so that I can relay the proper headers to the user. what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't safely say that all such exceptions will extend ElasticsearchException (e.g., a bad NullPointerException), but I like your idea of wrapping the ones that do not extend (as long as it's not wrapping it in an exception that sounds like the user can do something about it).

Copy link
Member

@martijnvg martijnvg Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasontedor Would using ExceptionsHelper#convertToElastic(...) helper method in ConfigurationUtils#newConfigurationException(...) or similar here be sufficient?

I think the excepting being thrown if the mustache template couldn't be compiled is a MustacheException, which gets wrapped by GeneralScriptException in ScriptService#compileInternal(...), which is what also should be fixed. Instead the lang-mustache should catch MustacheException exceptions with ScriptException.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using ExceptionsHelper#convertToElastic(...) helper method in ConfigurationUtils#newConfigurationException(...) or similar here be sufficient?

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update to use this helper. didn't know about it

@talevy talevy merged commit f7cd86e into elastic:master Jul 20, 2016
@talevy talevy deleted the rethrow-template-compile branch July 20, 2016 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v5.0.0-alpha5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants