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

Diagnostics break for the entire file when an empty message is posted #155531

Closed
lnicola opened this issue Jul 18, 2022 · 8 comments
Closed

Diagnostics break for the entire file when an empty message is posted #155531

lnicola opened this issue Jul 18, 2022 · 8 comments
Assignees
Labels
*caused-by-extension Issue identified to be caused by an extension

Comments

@lnicola
Copy link
Contributor

lnicola commented Jul 18, 2022

Does this issue occur when all extensions are disabled?: No

  • VS Code Version: 1.69.1
  • OS Version: Linux

Spotted in rust-lang/rust-analyzer#11404. I suspect the undefined in

if (!message) {
return undefined;
}
breaks the caller.

CC #5952

image

Repro (with rust-analyzer):

fn main() {
    $;
    compile_error!("");
    $;
}

image

image

image

@jrieken
Copy link
Member

jrieken commented Aug 16, 2022

This is thrown in the extension host (here) and indicates bad extension behaviour. Depending on how the extension is written this likely prevent further errors but not errors from other extension.

Closing as extension-caused since they must provide valid diagnostic objects

@jrieken jrieken closed this as completed Aug 16, 2022
@jrieken jrieken added the *caused-by-extension Issue identified to be caused by an extension label Aug 16, 2022
@lnicola
Copy link
Contributor Author

lnicola commented Aug 16, 2022

I don't think this is a bug in the extension. Rust code can legitimately emit compilation errors without a message. And the compiler does that too (for the related diagnostics), if I recall correctly.

@Veykril
Copy link

Veykril commented Aug 16, 2022

Curious but is it documented somewhere that the diagnostic message is not allowed to be empty? If not that should be at least written down somewhere.

Fwiw the language server protocol also does not say that a message has to be non-empty, so either that should be added to that there as well or in my eyes VSCode is missing something to handle that case there.

@lnicola
Copy link
Contributor Author

lnicola commented Aug 28, 2022

@jrieken would you mind reconsidering this, given the two comments above?

		if (!message) {
			throw new TypeError('message must be set');
		}

I don't even know if this is intentional. The check might be for a missing message, but given the weakly-typed nature of JS, it will also trigger on empty-but-present messages. What breaks if we replace the condition by if (message == null)?

@jrieken
Copy link
Member

jrieken commented Aug 29, 2022

Yes, this is very much intentional. The one change I should probably do is to also throw with whitespace-only strings. Diagnostics are user-facing elements, they represent an issue with source code and doing that without a message feels illogical.

Maybe I am not understanding your use-case but when would like to see an error squiggle (or entry in the problems views) without stating what the problem is? What's the use-case and how is that desirable?

@lnicola
Copy link
Contributor Author

lnicola commented Aug 29, 2022

The one change I should probably do is to also throw with whitespace-only strings.

You're not throwing away the empty diagnostics, you're completely breaking them for the whole extension.

What's the use-case and how is that desirable?

  1. Rust code, including libraries, can emit compiler errors with an empty message. That might not be a great experience for the users, but it's fully allowed and used. Sample (click the Run button). Some popular libraries do or did this at one point.
  2. Rust compiler errors include multiple spans. Notice how the one on &'a i32 has no message:

image

We expand them to multiple diagnostics, in order to show them nicely:

image

If you delete the first span, you throw away information from the compiler:

image

And of course, by throwing that exception, you're preventing diagnostics from working in the whole file (or even project/workspace, I don't remember), even those that do have an associated message.

We could duplicate the message from &'b i32 in this case, but I'm not sure that works every time, and it would crowd out the diagnostic list. I think we did something like this at one point.

This was reported to multiple times and in different forms, so it's not just a theoretical concern.

@jrieken
Copy link
Member

jrieken commented Aug 29, 2022

Why aren't you using DiagnosticRelatedInformation for such cases?

@lnicola
Copy link
Contributor Author

lnicola commented Aug 29, 2022

We are. As far as I know, this was/is also an issue for those.

And that doesn't fix the compiler_error! case.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*caused-by-extension Issue identified to be caused by an extension
Projects
None yet
Development

No branches or pull requests

6 participants