-
Notifications
You must be signed in to change notification settings - Fork 65
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
API for registering errors, warnings and informational messages #160
Conversation
const visitor = require("../visitor"); | ||
|
||
// Removes proxy rules -- that is, rules that only delegate to other rule. | ||
function removeProxyRules(ast, options) { | ||
function removeProxyRules(ast, options, session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, session
seems to be more frequently used parameter, but adding it as the second would be a breaking change.
// In order to preserve backward compatibility we cannot change `GrammarError` | ||
// constructor, nor throw another class of error: | ||
// - if we change `GrammarError` constructor, this will break plugins that | ||
// throws `GrammarError` | ||
// - if we throw another Error class, this will break parser clients that | ||
// catches GrammarError | ||
// | ||
// So we use a compromise: we throw an `GrammarError` with all found problems | ||
// in the `problems` property, but the thrown error itself is the first | ||
// registered error. | ||
// | ||
// Thus when the old client catches the error it can find all properties on | ||
// the Grammar error that it want. On the other hand the new client can | ||
// inspect the `problems` property to get all problems. | ||
if (this._firstError === null) { | ||
this._firstError = new GrammarError(...args); | ||
this._firstError.stage = this.stage; | ||
this._firstError.problems = this.problems; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the trick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost all very small English grammar nits. None of the substantive things I asked about are blocking.
// All problems if this error is thrown by the plugin and not at stage | ||
// checking phase | ||
this.stage = null; | ||
this.problems = [["error", message, location, diagnostics]]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think format()
should change as well, to do something with the problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Now all problems from problems
property printed each after aother, separated by the blank line:
error: problem 1
warning: problem 2
...
info: problem N
…and information messages
…tests Add new test: without main location and source
(review with "ignore whitespace changes" on)
I messed up and pushed a proposed change set to your branch without your permission. Apologies! Let me know how you want to move forward, please. |
All's fine. I leaved checkbox Allow edits and access to secrets by maintainers checked in the PR that is why you were able to do that. I approve your changes. |
Phew. Finally all necessary PRs are merged and I can provide this.
That is implementation of a Session API that I've mentioned early (well, couple of days turned into couple of weeks... but it worth it). Although I feared that a second commit could have to break backward compatibility, with the help of a small trick it was possible to avoid this. As a result, it turned out a little dirty, but without breaking changes.
The new API allows passes to register warnings, informational messages and errors and we can collect multiply errors in one compilation attempt -- as much as possible.
I've tried to explain everything in the README.md, so I will not repeat myself here. Just see the diff of the README.md.
Although it would be great to have this PR in the same version where we have improved the errors, it is possible that the changes here are too fundamental, so I don't rush you.