Skip to content

Commit f51a5b9

Browse files
authored
always print auth messages in TL, regardless of verbosity (#11551)
Part of dotnet/sdk#47602 ### Context With `NuGetInteractive=true` being passed in more scenarios as of dotnet/sdk#47226, the default verbosity for `dotnet run` is now `minimal` for user-present scenarios - that's gross. ### Changes Made Broadly what I'm trying to do here is not require passing `-v m` to loggers to get the authentication-related messages. Right now `dotnet run` does this and it's quite noisy compared to previous behavior. This changed because recently I made the SDK start passing `--interactive` when the user is at the keyboard (similar logic to Terminal Logger's own enablement), and `dotnet run` has logic to force verbosity to minimal when that happens so that the auth messages print where a user can see them. I kind of think of auth messages as messages that we should write regardless of verbosity (like errors are), so this is a step down that path for TL. This change ensures that auth messages are always written in the TL experience, as immediate messages. If this is accepted, then the SDK could remove the [special case it currently has](dotnet/sdk#47389). ### Testing Updated snapshot baselines, manual testing. ### Notes
2 parents 9d762bd + 71e9706 commit f51a5b9

7 files changed

+39
-30
lines changed

src/Build.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Linux.verified.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
directory/file(1,2,3,4): warning AA0000: Warning!
1+
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
2+
directory/file(1,2,3,4): warning AA0000: Warning!
23
directory/file(1,2,3,4): warning AA0000:
34
A
45
Multi

src/Build.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.OSX.verified.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
directory/file(1,2,3,4): warning AA0000: Warning!
1+
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
2+
directory/file(1,2,3,4): warning AA0000: Warning!
23
directory/file(1,2,3,4): warning AA0000:
34
A
45
Multi

src/Build.UnitTests/Snapshots/TerminalLogger_Tests.PrintBuildSummaryQuietVerbosity_FailedWithErrors.Windows.verified.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
directory/file(1,2,3,4): warning AA0000: Warning!
1+
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
2+
directory/file(1,2,3,4): warning AA0000: Warning!
23
directory/file(1,2,3,4): warning AA0000:
34
A
45
Multi
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
]9;4;3;\directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
22
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]ATTENTION: User interaction required.**********************************************************************To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate.**********************************************************************
3-
project succeeded with 2 warning(s) (0.2s)
4-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
5-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]ATTENTION: User interaction required.**********************************************************************To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate.**********************************************************************
63
[?25l
74
[?25h
8-
Build succeeded with 2 warning(s) in 5.0s
5+
Build succeeded in 5.0s
96
]9;4;0;\
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
1+
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
22
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]ATTENTION: User interaction required.**********************************************************************To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate.**********************************************************************
3-
project succeeded with 2 warning(s) (0.2s)
4-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
5-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]ATTENTION: User interaction required.**********************************************************************To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate.**********************************************************************
63
[?25l
74
[?25h
8-
Build succeeded with 2 warning(s) in 5.0s
5+
Build succeeded in 5.0s
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
]9;4;3;\directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
22
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]ATTENTION: User interaction required.**********************************************************************To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate.**********************************************************************
3-
project succeeded with 2 warning(s) (0.2s)
4-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]DeviceFlow: https://testfeed/index.json
5-
directory/file(1,2,3,4): warning AA0000: [CredentialProvider]ATTENTION: User interaction required.**********************************************************************To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate.**********************************************************************
63
[?25l
74
[?25h
8-
Build succeeded with 2 warning(s) in 5.0s
5+
Build succeeded in 5.0s
96
]9;4;0;\

src/Build/Logging/TerminalLogger/TerminalLogger.cs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public sealed partial class TerminalLogger : INodeLogger
3535
private const string FilePathPattern = " -> ";
3636

3737
#if NET
38-
private static readonly SearchValues<string> _immediateMessageKeywords = SearchValues.Create(["[CredentialProvider]", "--interactive"], StringComparison.OrdinalIgnoreCase);
38+
private static readonly SearchValues<string> _authProviderMessageKeywords = SearchValues.Create(["[CredentialProvider]", "--interactive"], StringComparison.OrdinalIgnoreCase);
3939
#else
40-
private static readonly string[] _immediateMessageKeywords = ["[CredentialProvider]", "--interactive"];
40+
private static readonly string[] _authProviderMessageKeywords = ["[CredentialProvider]", "--interactive"];
4141
#endif
4242

4343
private static readonly string[] newLineStrings = { "\r\n", "\n" };
@@ -874,14 +874,15 @@ private void MessageRaised(object sender, BuildMessageEventArgs e)
874874
}
875875
}
876876

877+
// auth provider messages should always be shown to the user.
878+
if (IsAuthProviderMessage(message))
879+
{
880+
RenderImmediateMessage(message);
881+
return;
882+
}
883+
877884
if (Verbosity > LoggerVerbosity.Quiet)
878885
{
879-
// Show immediate messages to the user.
880-
if (IsImmediateMessage(message))
881-
{
882-
RenderImmediateMessage(message);
883-
return;
884-
}
885886
if (e.Code == "NETSDK1057" && !_loggedPreviewMessage)
886887
{
887888
// The SDK will log the high-pri "not-a-warning" message NETSDK1057
@@ -984,21 +985,35 @@ private void WarningRaised(object sender, BuildWarningEventArgs e)
984985
{
985986
BuildEventContext? buildEventContext = e.BuildEventContext;
986987

988+
// auth provider messages are 'global' in nature and should be a) immediate reported, and b) not re-reported in the summary.
989+
if (IsAuthProviderMessage(e.Message))
990+
{
991+
RenderImmediateMessage(FormatWarningMessage(e, Indentation));
992+
return;
993+
}
994+
987995
if (buildEventContext is not null
988996
&& _projects.TryGetValue(new ProjectContext(buildEventContext), out TerminalProjectInfo? project)
989997
&& Verbosity > LoggerVerbosity.Quiet)
990998
{
991-
if ((!String.IsNullOrEmpty(e.Message) && IsImmediateMessage(e.Message!)) ||
992-
IsImmediateWarning(e.Code))
999+
// If the warning is not a 'global' auth provider message, but is immediate, we render it immediately
1000+
// but we don't early return so that the project also tracks it.
1001+
if (IsImmediateWarning(e.Code))
9931002
{
9941003
RenderImmediateMessage(FormatWarningMessage(e, Indentation));
9951004
}
9961005

1006+
// This is the general case - _most_ warnings are not immediate, so we add them to the project summary
1007+
// and display them in the per-project and final summary.
9971008
project.AddBuildMessage(TerminalMessageSeverity.Warning, FormatWarningMessage(e, TripleIndentation));
9981009
}
9991010
else
10001011
{
1001-
// It is necessary to display warning messages reported by MSBuild, even if it's not tracked in _projects collection or the verbosity is Quiet.
1012+
// It is necessary to display warning messages reported by MSBuild,
1013+
// even if it's not tracked in _projects collection or the verbosity is Quiet.
1014+
// The idea here (similar to the implementation in ErrorRaised) is that
1015+
// even in Quiet scenarios we need to show warnings/errors, even if not in
1016+
// full project-tree view
10021017
RenderImmediateMessage(FormatWarningMessage(e, Indentation));
10031018
_buildWarningsCount++;
10041019
}
@@ -1009,11 +1024,11 @@ private void WarningRaised(object sender, BuildWarningEventArgs e)
10091024
/// </summary>
10101025
/// <param name="message">Raised event.</param>
10111026
/// <returns>true if marker is detected.</returns>
1012-
private bool IsImmediateMessage(string message) =>
1027+
private bool IsAuthProviderMessage(string? message) =>
10131028
#if NET
1014-
message.AsSpan().ContainsAny(_immediateMessageKeywords);
1029+
message is not null && message.AsSpan().ContainsAny(_authProviderMessageKeywords);
10151030
#else
1016-
_immediateMessageKeywords.Any(imk => message.IndexOf(imk, StringComparison.OrdinalIgnoreCase) >= 0);
1031+
message is not null && _authProviderMessageKeywords.Any(imk => message.IndexOf(imk, StringComparison.OrdinalIgnoreCase) >= 0);
10171032
#endif
10181033

10191034

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy