Skip to content

Add option to redact token details from parser error messages #3618

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

Merged
merged 4 commits into from
Jun 7, 2024

Conversation

dondonz
Copy link
Member

@dondonz dondonz commented Jun 5, 2024

Addresses #3617

Adds an option to redact the token from parser error messages. Note that the default behaviour will be the same as before, by default error messages provide token information if available, to assist with debugging.

There are three parsing messages to be redacted:

  • InvalidSyntax.full
  • InvalidSyntaxBail.full
  • InvalidSyntaxMoreTokens.full

@@ -1188,4 +1188,70 @@ triple3 : """edge cases \\""" "" " \\"" \\" edge cases"""
"\"\t\" scalar A" | _
}

def "can redact tokens in InvalidSyntax parser error message"() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Finding the right offending cases was the hard bit!

These tests cover the 3 message strings to be redacted

  • InvalidSyntax.full
  • InvalidSyntaxBail.full
  • InvalidSyntaxMoreTokens.full


defaultOperationOptions.getMaxTokens() == 15_000
defaultOperationOptions.getMaxWhitespaceTokens() == 200_000
defaultOperationOptions.isCaptureSourceLocation()
!defaultOperationOptions.isCaptureLineComments()
!defaultOperationOptions.isCaptureIgnoredChars()
defaultOptions.isReaderTrackData()
Copy link
Member Author

Choose a reason for hiding this comment

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

Typo from the past


defaultSdlOptions.getMaxCharacters() == Integer.MAX_VALUE
defaultSdlOptions.getMaxTokens() == Integer.MAX_VALUE
defaultSdlOptions.getMaxWhitespaceTokens() == Integer.MAX_VALUE
defaultSdlOptions.isCaptureSourceLocation()
defaultSdlOptions.isCaptureLineComments()
!defaultSdlOptions.isCaptureIgnoredChars()
defaultOptions.isReaderTrackData()
Copy link
Member Author

Choose a reason for hiding this comment

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

Typo from the past

@ee-usgs
Copy link

ee-usgs commented Jun 6, 2024

This looks good to me!

@@ -189,6 +192,7 @@ public static void setDefaultSdlParserOptions(ParserOptions options) {
private final int maxTokens;
private final int maxWhitespaceTokens;
private final int maxRuleDepth;
private final boolean redactTokenParserErrorMessages;
Copy link
Member

Choose a reason for hiding this comment

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

defaults to false - great

@@ -319,6 +332,7 @@ public static class Builder {
private int maxTokens = MAX_QUERY_TOKENS;
private int maxWhitespaceTokens = MAX_WHITESPACE_TOKENS;
private int maxRuleDepth = MAX_RULE_DEPTH;
private boolean redactTokenParserErrorMessages = false;
Copy link
Member

Choose a reason for hiding this comment

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

defaulted to false - great!!

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Nice one

@dondonz dondonz added this pull request to the merge queue Jun 7, 2024
Merged via the queue into master with commit b38dbd9 Jun 7, 2024
1 check passed
@dondonz
Copy link
Member Author

dondonz commented Jun 7, 2024

@ee-usgs FYI I merged this PR into master. This will kick off a master build deployment, in case you want to test (of course, no obligation to do anything, you've given me very detailed info already!)

Our master build versions contain the date in UTC and the git short hash in the name. Look for it in your favourite Maven website, this one is most up to date: https://repo1.maven.org/maven2/com/graphql-java/graphql-java/. It takes a short while to land in Maven, it'll land soon.

Thanks again for the suggestion!

@dondonz dondonz deleted the toggle-offending-tokens branch June 7, 2024 06:08
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