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

API for registering errors, warnings and informational messages #160

Merged
merged 6 commits into from
Oct 24, 2021

Conversation

Mingun
Copy link
Member

@Mingun Mingun commented May 28, 2021

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.

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) {
Copy link
Member Author

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.

Comment on lines +34 to +58
// 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;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

That is the trick

Copy link
Contributor

@hildjj hildjj left a 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.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
docs/documentation.html Show resolved Hide resolved
lib/compiler/index.js Outdated Show resolved Hide resolved
lib/compiler/session.js Show resolved Hide resolved
// 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]];
}
Copy link
Contributor

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.

Copy link
Member Author

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

test/behavior/generated-parser-behavior.spec.js Outdated Show resolved Hide resolved
@Mingun Mingun changed the title API for registering multipli errors, warnings and informational messages API for registering errors, warnings and informational messages Oct 23, 2021
@hildjj
Copy link
Contributor

hildjj commented Oct 23, 2021

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.

@Mingun
Copy link
Member Author

Mingun commented Oct 24, 2021

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.

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.

None yet

2 participants