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

Update monitor cmdlet warning message #17129

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Monitor/Monitor/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Fixed an issue where users could not correctly ignore warning messages after setting environment variables [#17013]

## Version 3.0.0
* Added new properties EventName, Category, ResourceProviderName, OperationName, Status, SubStatus with type string as output for command Get-AzLog [#15833]
Expand Down
48 changes: 27 additions & 21 deletions src/Monitor/Monitor/MonitorCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,24 @@ protected string GetCmdletName()
/// <param name="withTimeStamp">true if the message should include a timestamp, false (default) it no timestamp should be included</param>
protected void WriteIdentifiedWarning(string cmdletName, string topic, string message, bool withTimeStamp = false)
{
string formattedMessage = string.Format(
CultureInfo.InvariantCulture,
"[{0}] {1}: {2}",
cmdletName,
topic,
message);

if (withTimeStamp)
{
WriteWarningWithTimestamp(formattedMessage);
}
else
string supressWarningOrErrorValue = System.Environment.GetEnvironmentVariable(BreakingChangeAttributeHelper.SUPPRESS_ERROR_OR_WARNING_MESSAGE_ENV_VARIABLE_NAME);
Copy link
Contributor

@VeryEarly VeryEarly Feb 17, 2022

Choose a reason for hiding this comment

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

please check line 96 - 101, remove duplicate logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, please check it.

bool supressWarningOrError;
Boolean.TryParse(supressWarningOrErrorValue, out supressWarningOrError);
if (!supressWarningOrError)
{
WriteWarning(formattedMessage);
string formattedMessage = string.Format(
CultureInfo.InvariantCulture, "{0}{1}{2}",
string.IsNullOrEmpty(cmdletName) ? cmdletName : "[" + cmdletName + "] ",
string.IsNullOrEmpty(topic) ? topic : topic + ": ",
message);
if (withTimeStamp)
{
WriteWarningWithTimestamp(formattedMessage);
}
else
{
WriteWarning(formattedMessage);
}
}
}

Expand All @@ -87,16 +91,18 @@ public override void ExecuteCmdlet()
string reasonPhrase = null;
string message = null;
string exName = null;
string supressWarningOrErrorValue = System.Environment.GetEnvironmentVariable(BreakingChangeAttributeHelper.SUPPRESS_ERROR_OR_WARNING_MESSAGE_ENV_VARIABLE_NAME);
try
{
bool supressWarningOrError;
Boolean.TryParse(supressWarningOrErrorValue, out supressWarningOrError);
if (!supressWarningOrError)
{
WriteWarningWithTimestamp("The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.");
WriteWarningWithTimestamp("The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.");
}
this.WriteIdentifiedWarning(
Copy link
Contributor

Choose a reason for hiding this comment

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

WriteIdentifiedWarning("The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.");
WriteIdentifiedWarning("The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

cmdletName: "",
topic: "",
message: "*** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.",
withTimeStamp: true);
this.WriteIdentifiedWarning(
cmdletName: "",
topic: "",
message: "*** The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.",
withTimeStamp: true);
this.ProcessRecordInternal();
}
catch (AggregateException ex)
Expand Down