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

Convert other errors to diagnostics when possible #183

Merged
merged 7 commits into from
May 6, 2022
Merged

Conversation

rictic
Copy link
Member

@rictic rictic commented May 4, 2022

I think this converts the rest of the error events that are caused by file locations to use diagnostics.

The commits are pretty targeted and should be fairly easy to review one at a time.

@rictic rictic requested a review from aomarks May 4, 2022 18:36
@aomarks
Copy link
Member

aomarks commented May 4, 2022

Looks like some Windows failures relating to path separators. Probably need to substitute ${pathlib.sep} into some test cases.

Base automatically changed from more-diagnostics to main May 4, 2022 19:13
@rictic rictic force-pushed the yet-more-diagnostics branch from bda3986 to 63f6b54 Compare May 4, 2022 19:19
@rictic
Copy link
Member Author

rictic commented May 4, 2022

(this is ready for review, the errors are github cache errors, will rerun shortly)

rictic added 6 commits May 5, 2022 16:49
I was thinking that we wanted a Location in case we wanted to combine this error with information about what's requesting the script, but we can always pull the Location off of the Diagnostic in that case, and in the meantime we get a nice diagnostic.
It was sad to lose the cool ascii diagrams, but all of the wonderful logic got reused, and in the case of multi package cycles I think this will be clearer.
We're already passing in the script placeholder, so it can just throw a proper WireitError now.

Also remove invalid-package-json error, as it's now replaced by json-syntax-error.
@rictic rictic force-pushed the yet-more-diagnostics branch from 63f6b54 to 0b77f65 Compare May 5, 2022 21:49
Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

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

Cool!

}
case 'script-not-found':
case 'duplicate-dependency':
case 'script-not-wireit':
Copy link
Member

Choose a reason for hiding this comment

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

We could collapse some or all of these validation error interfaces into one, now that the formatter isn't really responsible for formatting them anymore.

Copy link
Member

Choose a reason for hiding this comment

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

(doesn't have to be this PR, just a thought)

src/analyzer.ts Outdated Show resolved Hide resolved
src/analyzer.ts Outdated Show resolved Hide resolved
// Display the trail of scripts and indicate where the loop is, like
// this:
//
// a
Copy link
Member

Choose a reason for hiding this comment

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

😢

const dependencyNode = current.dependenciesAst?.children?.[nextIdx];
// Use the actual value in the array, because this could refer to
// a script in another package.
const nextName =
Copy link
Member

@aomarks aomarks May 6, 2022

Choose a reason for hiding this comment

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

It seems like a difference here is that we used to generate a display label for each script that was always relative to the current package (see DefaultLogger.#label ), so that everything was phrased relative to where the user currently is. But now it uses the verbatim specifier from the dependency array, which is relative to each package.

Also, we'll probably support $WORKSPACES:build syntax (#23), to mean "all build scripts in this package's workspaces". So in that case, the literal dependency specifier wouldn't actually tell you what the specific package is.

So I think it might be good to preserve the DefaultLogger.#label method behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

True, but the printed trail has the filenames relative to the current package so that you can follow along. Like, if we there was a cycle of "foo" -> "build" -> "$WORKSPACES:build" -> "./child:build" -> "foo" then the diagnostic printer would print (leaving out line and column numbers):

X package.json Cycle detected in dependencies of "foo"
    "foo": {
    ~~~~~

    package.json "foo" points to "build"
        "dependencies": ["build"],
                         ~~~~~~~

    package.json "build" points to "$WORKSPACES:build"
        "dependencies": ["$WORKSPACES:build"],
                         ~~~~~~~~~~~~~~~~~~~

    ./child/package.json "build" points back to "..:foo"
        "dependencies": ["..:foo"],
                         ~~~~~~~~

Or in the case where the loop is more like "./child:build" -> "./child:foo" -> "build" -> "$WORKSPACES:build" and starting from the child directory then it would like:

X package.json Cycle detected in dependencies of "build"
    "build": {
    ~~~~~~~

    package.json "build" points to "foo"
        "dependencies": ["foo"],
                         ~~~~~

    package.json "foo" points to "..:build"
        "dependencies": ["..:build"],
                         ~~~~~~~~~~

    ../package.json "build" points back to "$WORKSPACES:build"
        "dependencies": ["$WORKSPACES:build"],
                         ~~~~~~~~~~~~~~~~~~~

That's a bit harder to read. Maybe we'd want that last line to read more like this?

    ../package.json "build" points back to "$WORKSPACES:build" which includes "child:build"

What would your ideal error message look like?

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 guess we could generate a diagnostic for the IDE with all the supplemental locations but keep the previous error formatting in the logger

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I see it is not so simple.

Was sort of thinking something like this:

X package.json Cycle detected in dependencies of "build"
    "build": {
    ~~~~~~~

    "build" points to "foo"
        "dependencies": ["foo"],
                         ~~~~~

    "foo" points to "..:build"
        "dependencies": ["..:build"],
                         ~~~~~~~~~~

    "..:build" points back to "build"
        "dependencies": ["$WORKSPACES:build"],
                         ~~~~~~~~~~~~~~~~~~~

I do like that it's just a single, consistent syntax for referring to a script, which matches exactly how you would specify that script in the package you started from.

But then we lose the package.json references, which are required and/or useful? If you keep them but use the consistent script specifier, then it seems sort of confusing because it's no longer relative to each line's package.json.

X package.json Cycle detected in dependencies of "build"
    "build": {
    ~~~~~~~

    package.json "build" points to "foo"
        "dependencies": ["foo"],
                         ~~~~~

    package.json "foo" points to "..:build"
        "dependencies": ["..:build"],
                         ~~~~~~~~~~

    ../package.json "..:build" points back to "build"
        "dependencies": ["$WORKSPACES:build"],
                         ~~~~~~~~~~~~~~~~~~~

Meh, I'm also fine with it the way it already was in this PR.

I kind of liked the cycle diagram (which is actually taken exactly from Bazel), but it's also really nice to have symmetrical errors on the console vs in the editor, so I'm fine with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

The package.json references are useful so that someone can cmd-click on them to jump directly to that specific location, as well as to power the supplemental locations feature in the language server provider, which does fancy presentation of the diagnostic in the editor.

One other consideration is that this way of displaying it is much wordier and longer than the cycle diagram, but I feel like cycles are rare in the wild, and when you do have one it's better for it to be longer like this.

@rictic rictic requested a review from aomarks May 6, 2022 15:40
@rictic rictic merged commit 287f5eb into main May 6, 2022
@rictic rictic deleted the yet-more-diagnostics branch May 6, 2022 18:30
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.

2 participants