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

Improve validation error messages for unknown property and json mapping exceptions #5044

Merged

Conversation

graytaylor0
Copy link
Member

@graytaylor0 graytaylor0 commented Oct 10, 2024

Description

This change improves the error messaging for unknown plugin properties and json mapping exceptions

Old error for unknown property

    entry-pipeline.processor.parse_json: caused by: Unrecognized field "destiatio" (class org.opensearch.dataprepper.plugins.processor.parse.json.ParseJsonProcessorConfig), not marked as ignorable (8 known properties: "tags_on_failure", "handle_failed_events", "parse_when", "source", "pointer", "destination", "delete_source", "overwrite_if_destination_exists"]) at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: org.opensearch.dataprepper.plugins.processor.parse.json.ParseJsonProcessorConfig["destiatio"]) caused by: Unrecognized field "destiatio" (class org.opensearch.dataprepper.plugins.processor.parse.json.ParseJsonProcessorConfig), not marked as ignorable (8 known properties: "tags_on_failure", "handle_failed_events", "parse_when", "source", "pointer", "destination", "delete_source", "overwrite_if_destination_exists"]) at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: org.opensearch.dataprepper.plugins.processor.parse.json.ParseJsonProcessorConfig["destiatio"])

New error for unknown property

1. entry-pipeline.processor.parse_json: caused by: Parameter "destintio" for plugin "parse_json" does not exist. Available options include [tags_on_failure, handle_failed_events, parse_when, source, pointer, destination, delete_source, overwrite_if_destination_exists]. Did you mean "destination"?

Issues Resolved

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

final Optional<String> closestRecommendation = getClosestField(e);

if (closestRecommendation.isPresent()) {
errorMessage += " Did you mean \"" + closestRecommendation.get() + "\"?";
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should come first.

Perhaps:

1. entry-pipeline:processor:parse_json: caused by: Parameter "destintio" for plugin "parse_json" does not exist. Did you mean "destination"? Other available options include [tags_on_failure, handle_failed_events, parse_when, source, pointer, destination, delete_source, overwrite_if_destination_exists]. 

When not present, it could be:

  1. entry-pipeline:processor:parse_json: caused by: Parameter "blah" for plugin "parse_json" does not exist. Available options include [tags_on_failure, handle_failed_events, parse_when, source, pointer, destination, delete_source, overwrite_if_destination_exists].

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually feel like it is easier to see the recommendation when it's at the end with just a glance. If the entire message is read in order then the recommendation coming first is good, but it does seem easier to see when it's at the end.

Copy link
Member Author

@graytaylor0 graytaylor0 Oct 10, 2024

Choose a reason for hiding this comment

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

entry-pipeline:processor:parse_json: caused by: Parameter "destintio" for plugin "parse_json" does not exist. Available options include [tags_on_failure, handle_failed_events, parse_when, source, pointer, destination, delete_source, overwrite_if_destination_exists]. Did you mean "destination"?

vs.

entry-pipeline:processor:parse_json: caused by: Parameter "destintio" for plugin "parse_json" does not exist. Did you mean "destination"? Other available options include [tags_on_failure, handle_failed_events, parse_when, source, pointer, destination, delete_source, overwrite_if_destination_exists].

Copy link
Member

Choose a reason for hiding this comment

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

Yea, that makes sense.

We probably need to make better use of newlines. Then it would be much cleaner.

entry-pipeline:processor:parse_json: caused by: 

Parameter "destintio" for plugin "parse_json" does not exist. Available options include [tags_on_failure, handle_failed_events, parse_when, source, pointer, destination, delete_source, overwrite_if_destination_exists]. 

Did you mean "destination"?

try {
return objectMapper.convertValue(settingsMap, pluginConfigurationType);
} catch (final Exception e) {
pluginConfigurationErrorHandler.handleException(pluginSetting, e);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pluginConfigurationErrorHandler.handleException(pluginSetting, e);
throw pluginConfigurationErrorHandler.handleException(pluginSetting, e);

You can change handleException to return an Exception.

Then you should be able to remove the throw below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will make this change

private String getParameterPath(final List<JsonMappingException.Reference> path) {
return path.stream()
.map(JsonMappingException.Reference::getFieldName)
.collect(Collectors.joining("."));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should join with : to remain consistent with the top-level?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with consistency, but maybe the consistent thing to do would be to use . everywhere?

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with either as long as it is consistent.

chenqi0805
chenqi0805 previously approved these changes Oct 10, 2024
Copy link
Collaborator

@chenqi0805 chenqi0805 left a comment

Choose a reason for hiding this comment

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

Thanks for the enhancement!

@graytaylor0 graytaylor0 force-pushed the ValidationErrorImprovements branch from 7d6dd90 to aa3cb24 Compare October 11, 2024 19:38
@graytaylor0 graytaylor0 dismissed dlvenable’s stale review October 14, 2024 15:48

addressed review comments

@dlvenable dlvenable merged commit c0061af into opensearch-project:main Oct 14, 2024
46 of 47 checks passed
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 this pull request may close these issues.

3 participants