Skip to content

Fix ParseVBErrorOrWarning#47833

Merged
jaredpar merged 14 commits intodotnet:mainfrom
Youssef1313:patch-7
Jan 20, 2022
Merged

Fix ParseVBErrorOrWarning#47833
jaredpar merged 14 commits intodotnet:mainfrom
Youssef1313:patch-7

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

Fixes #47790

Not sure how/where to write tests for this. I was also unable to test this locally due to getting some unrelated exception (#47562 (comment)).

@Youssef1313 Youssef1313 requested a review from a team as a code owner September 18, 2020 14:50
@adambiser
Copy link
Copy Markdown
Contributor

adambiser commented Sep 18, 2020

Mightn't the error description contain parentheses? If so, using LastIndexOf would grab it instead.
I wonder whether it would be better to use IndexOf("):") since that combination isn't part of a valid path, so the first occurrence should be after the line number.

@Youssef1313
Copy link
Copy Markdown
Member Author

@adambiser Yeah that's correct. Fixed.

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 2). @jaredpar, can you take a second look?

@AlekseyTs
Copy link
Copy Markdown
Contributor

I think we need to find a way to test the change.

@Youssef1313
Copy link
Copy Markdown
Member Author

@AlekseyTs I agree, but I'm unfortunately unaware of how to test this.

@jinujoseph jinujoseph added Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Sep 25, 2020
/// <param name="singleLine">The line to parse</param>
/// <param name="messageImportance">The MessageImportance to use when reporting the error.</param>
internal void ParseVBErrorOrWarning(string singleLine, MessageImportance messageImportance)
private void ParseVBErrorOrWarning(string singleLine, MessageImportance messageImportance)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree in general that it's hard to test the various Tasks because it becomes more of an integration test with MSBuild. In this particular case though we're effectively altering how VB error messages are parsed in the task. I think we could factor this method a bit, by either adding a static method or by just newing up the Task in test and setting the properies, and use that to validate this change works (and stays correct going forward).

@adambiser
Copy link
Copy Markdown
Contributor

There is a pull request on Youssef1313:patch-7 that has tests and fixes the issue. The fix here does not parse what comes from vbc correctly (should be a space between the end parenthesis and the colon). It has been waiting for a couple of weeks. Should I close it and start a separate pull request for this issue?

@333fred
Copy link
Copy Markdown
Member

333fred commented Dec 10, 2020

It's possible that @Youssef1313 didn't know the request was there?

@adambiser
Copy link
Copy Markdown
Contributor

Possibly, but I thought that sending a pull request also sent a notification.

@333fred
Copy link
Copy Markdown
Member

333fred commented Dec 10, 2020

Possibly, but I thought that sending a pull request also sent a notification.

On forks, I believe notifications are actually off by default.

@adambiser
Copy link
Copy Markdown
Contributor

OK. I had forked from his fork so I thought he would get notification of the pull request to his repo.

Verifies the text used for Microsoft.Build.Tasks.CodeAnalysis.UnitTests.CheckErrorAndWarningParsing.
ErrorLoggerEngine was added to capture the parse results as produced by Microsoft.Build.Shared.EventArgsFormatting.
Copy link
Copy Markdown
Member Author

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

Thanks @adambiser. That really helped a lot. And sorry for the delay, I didn't get notified of your PR on my fork.

Comment on lines +54 to +60
public void LogCustomEvent(CustomBuildEventArgs eventArgs)
{
}

public void LogMessageEvent(BuildMessageEventArgs eventArgs)
{
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should throw NotImplementedException instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And thank you, too. I had assumed you would get a notification since I had forked from you instead of the main project. Figured other things were filling your time, as is easy to happen nowadays. But now I know.

As for NotImplementedException, I don't think so. I added the class solely to get to the warning and error output, though I guess given the class's limited usage, throwing NotImplementedException in both probably won't affect things.
I also was unaware of how to test this and ended up with two. Not sure whether they will approve of the tests or not though.

_formatErrorMethod = formattingClass.GetMethod("FormatEventMessage", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any,
new Type[] { typeof(BuildErrorEventArgs) }, null) ?? throw new Exception("Could not find FormatEventMessage(BuildErrorEventArgs).");
_formatWarningMethod = formattingClass.GetMethod("FormatEventMessage", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any,
new Type[] { typeof(BuildWarningEventArgs) }, null) ?? throw new Exception("Could not find FormatEventMessage(BuildWarningEventArgs).");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using reflection here concerns me greatly. @rainersigwald, do you have suggestions for a better way to accomplish this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For context, we're trying to test our parsing of msbuild error message output in Vbc.exe

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, missed this. I agree that this feels icky but I'm afraid I don't have a better idea at the moment.

@333fred
Copy link
Copy Markdown
Member

333fred commented Jan 8, 2021

@jaredpar, if you have some time can you take a look at this PR?

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 6). Thanks for figuring out a way to unittest the change.

@jcouv jcouv closed this Jan 26, 2021
@jcouv jcouv reopened this Jan 26, 2021
@jcouv jcouv self-assigned this Jan 26, 2021
@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jan 27, 2021

@jaredpar @RikkiGibson Something strange is happening with CI. The Spanish legs fail after retry, but when I try to get details I get "Build not found" (and no details). Any clues?

@RikkiGibson
Copy link
Copy Markdown
Member

The build might be too old to retry. I suggest merging master into the PR branch.

@adambiser
Copy link
Copy Markdown
Contributor

The unit tests fail in Spanish because it's checking for the English error message text.

https://github.com/dotnet/roslyn/pull/47833/files#diff-10b671e15f3cd08b75ffd476f257613f8f99459752c107ba458ae68def5c02fc

Assert.Contains("\Test Path (123)\hellovb.vb(6) : warning BC40008: 'Public Property x As Integer' is obsolete.", output.ToString())
Assert.Contains("\Test Path (123)\hellovb.vb(6) : error BC30512: Option Strict On disallows implicit conversions from 'Double' to 'Integer'.", output.ToString())
Assert.Contains("\Test Path (123)\hellovb.vb(7) : error BC30451: 'asdf' is not declared. It may be inaccessible due to its protection level.", output.ToString())

But in Spanish it should check for

\Test Path (123)\hellovb.vb(6) : warning BC40008: 'Public Property x As Integer' está obsoleto.
\Test Path (123)\hellovb.vb(6) : error BC30512: Option Strict On no permite conversiones implícitas de 'Double' a 'Integer'.
\Test Path (123)\hellovb.vb(7) : error BC30451: 'asdf' no está declarado. Puede que sea inaccesible debido a su nivel de protección.

I guess it needs <ConditionalFact(GetType(IsEnglishLocal))> to be skipped for the Spanish checks?

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jan 27, 2021

Thanks @adambiser!
@Youssef1313 I'll let you update. Thanks

@jcouv jcouv marked this pull request as draft January 27, 2021 06:57
Base automatically changed from master to main March 3, 2021 23:52
@Youssef1313 Youssef1313 marked this pull request as ready for review January 18, 2022 11:52
@Youssef1313
Copy link
Copy Markdown
Member Author

Sorry for the delay here. The last commit should hopefully pass CI.

@jaredpar jaredpar merged commit 094bee3 into dotnet:main Jan 20, 2022
@ghost ghost added this to the Next milestone Jan 20, 2022
@Youssef1313 Youssef1313 deleted the patch-7 branch January 21, 2022 05:35
333fred added a commit to 333fred/roslyn that referenced this pull request Jan 21, 2022
* upstream/main: (1035 commits)
  Add missing header
  Mark IVSTypeScriptFormattingServiceImplementation as optional, but require it in the constructor
  Fix Go To Base for a symbol with a single metadata location (dotnet#58965)
  [EnC] Store entire spans instead of line deltas (dotnet#58831)
  Delete CodeAnalysisRules.ruleset (dotnet#58968)
  Allow xml docs to still be created when 'emit metadata only' is on. (dotnet#57667)
  Fix ParseVBErrorOrWarning (dotnet#47833)
  Update parameter nullability to match implementation
  Ensure CSharpUseParameterNullCheckingDiagnosticAnalyzer works with nullable parameters
  Add tests for issues fixed by previous PR (dotnet#58764)
  Update src/Features/CSharp/Portable/Completion/CompletionProviders/ExplicitInterfaceMemberCompletionProvider.CompletionSymbolDisplay.cs
  Disallow null checking discard parameters (dotnet#58952)
  Add extension method
  Escape type arguments
  Few fixes
  Update tests.
  Add Analyzers layer to CODEOWNERS
  Add formatting analyzer test for param nullchecking (dotnet#58936)
  Move reading HideAdvancedMembers option up (dotnet#58747)
  List patterns: Slice value is assumed to be never null (dotnet#57457)
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P1 Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building VB.NET project can report errors with invalid paths when the file path contains a number within parentheses

9 participants