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

Make malformed configuration exceptions typed #544

Closed
wants to merge 1 commit into from

Conversation

abishekvashok
Copy link
Contributor

A malformed configuration exception occurs when either the taint.config
file is not found or it is not a valid json file. During the validation
of taint.config file with the json specs, we raised an exception if it
was illegal.

Now added code to pretty print the exception via Log.error and specify
the line number and column number along with the file name.

Since YoJSON doesn't expose or store line numbers, this is implemented
by creating a custom Bi_output buffer and specifying it to YoJSON so
that YoJSON uses it for parsing and the last line of the contents would
be the line in which the error occured and the position and length of
such the last line would give us the line number and column number of
the error.

Test Plan

  • Compile the source from scratch
  • Malform a taint.config file by deleting a , or in some other way
  • Run pyre analyze (with $PYRE_BINARY pointing to the newly built binary)
  • See the new error instead of an exception
  • Restore taint.config to initial version
  • Run pyre analyze again to make sure nothing is broken with this change :)

Before this change:

ƛ Pyre encountered an internal exception: ("Taint__TaintConfiguration.MalformedConfiguration(\"/Users/abishekvashok/projects/stubs/stubs/taint/core_privacy_security/taint.config\", \"Line 7, bytes 4-37:\\nExpected ',' or '}' but found '{\\n      \\\"name\\\": \\\"Demo\\\",\\n      \\\"co'\")")

After this change:
Screenshot 2021-11-24 at 4 50 48 PM

Fixes part of: MLH-Fellowship#82
Signed-off-by: Abishek V Ashok [email protected]

A malformed configuration exception occurs when either the taint.config
file is not found or it is not a valid json file. During the validation
of taint.config file with the json specs, we raised an exception if it
was illegal.

Now added code to pretty print the exception via Log.error and specify
the line number and column number along with the file name.

Since YoJSON doesn't expose or store line numbers, this is implemented
by creating a custom Bi_output buffer and specifying it to YoJSON so
that YoJSON uses it for parsing and the last line of the contents would
be the line in which the error occured and the position and length of
such the last line would give us the line number and column number of
the error.

Signed-off-by: Abishek V Ashok <[email protected]>
@abishekvashok
Copy link
Contributor Author

Just heard that Bi_outbuf would be invalidated in the next release of YoJSON :/

I am thinking of closing this

@facebook-github-bot
Copy link
Contributor

@0xedward has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@abishekvashok
Copy link
Contributor Author

@0xedward closing due to above comment :)

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

Successfully merging this pull request may close these issues.

2 participants