2017-01-12 23:42:36 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
2017-01-30 22:36:44 +00:00
|
|
|
namespace Microsoft.DotNet.Cli.Utils
|
2017-01-12 23:42:36 +00:00
|
|
|
{
|
|
|
|
internal static class ExceptionExtensions
|
|
|
|
{
|
2017-02-01 02:48:14 +00:00
|
|
|
public static TException DisplayAsError<TException>(this TException exception)
|
|
|
|
where TException : Exception
|
|
|
|
{
|
|
|
|
exception.Data.Add(CLI_User_Displayed_Exception, true);
|
|
|
|
return exception;
|
|
|
|
}
|
|
|
|
|
2017-01-12 23:42:36 +00:00
|
|
|
public static void ReportAsWarning(this Exception e)
|
|
|
|
{
|
|
|
|
Reporter.Verbose.WriteLine($"Warning: Ignoring exception: {e.ToString().Yellow()}");
|
|
|
|
}
|
2017-01-30 22:36:44 +00:00
|
|
|
|
|
|
|
public static bool ShouldBeDisplayedAsError(this Exception e) =>
|
|
|
|
e.Data.Contains(CLI_User_Displayed_Exception);
|
|
|
|
|
|
|
|
internal const string CLI_User_Displayed_Exception = "CLI_User_Displayed_Exception";
|
2017-01-12 23:42:36 +00:00
|
|
|
}
|
|
|
|
}
|