mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
* [Analyzers][AdvancedPaste] Apply fix for SA1516 * [Analyzers][EnvironmentVariables] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Peek] Apply fix for SA1516 * [Analyzers][PreviewPane] Apply fix for SA1516 * [Analyzers][FancyZones] Apply fix for SA1516 * [Analyzers][PT Run][Plugins] Apply fix for SA1516 * [Analyzers][PT Run] Apply fix for SA1516 * [Analyzers][PT Run][Wox] Apply fix for SA1516 * [Analyzers][Common] Apply fix for SA1516 * [Analyzers][ImageResizer] Apply fix for SA1516 * [Analyzers][ColorPicker] Apply fix for SA1516 * [Analyzers][MouseUtils] Apply fix for SA1516 * [Analyzers][DSC Schema Generator] Apply fix for SA1516 * [Analyzers][FileLocksmith] Apply fix for SA1516 * [Analyzers][Hosts] Apply fix for SA1516 * [Analyzers][MeasureTool] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1516 * [Analyzers][TextExtractor] Apply fix for SA1516 * [Analyzers][Workspaces] Apply fix for SA1516 * [Analyzers][Awake] Apply fix for SA1516 * [Analyzers][PowerAccent] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Settings] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1616
59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using Wox.Plugin;
|
|
using Wox.Plugin.Logger;
|
|
|
|
namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
|
{
|
|
internal static class ErrorHandler
|
|
{
|
|
/// <summary>
|
|
/// Method to handles errors while calculating
|
|
/// </summary>
|
|
/// <param name="icon">Path to result icon.</param>
|
|
/// <param name="isGlobalQuery">Bool to indicate if it is a global query.</param>
|
|
/// <param name="queryInput">User input as string including the action keyword.</param>
|
|
/// <param name="errorMessage">Error message if applicable.</param>
|
|
/// <param name="exception">Exception if applicable.</param>
|
|
/// <returns>List of results to show. Either an error message or an empty list.</returns>
|
|
/// <exception cref="ArgumentException">Thrown if <paramref name="errorMessage"/> and <paramref name="exception"/> are both filled with their default values.</exception>
|
|
internal static List<Result> OnError(string icon, bool isGlobalQuery, string queryInput, string errorMessage, Exception exception = default)
|
|
{
|
|
string userMessage;
|
|
|
|
if (errorMessage != default)
|
|
{
|
|
Log.Error($"Failed to calculate <{queryInput}>: {errorMessage}", typeof(Calculator.Main));
|
|
userMessage = errorMessage;
|
|
}
|
|
else if (exception != default)
|
|
{
|
|
Log.Exception($"Exception when query for <{queryInput}>", exception, exception.GetType());
|
|
userMessage = exception.Message;
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException("The arguments error and exception have default values. One of them has to be filled with valid error data (error message/exception)!");
|
|
}
|
|
|
|
return isGlobalQuery ? new List<Result>() : new List<Result> { CreateErrorResult(userMessage, icon) };
|
|
}
|
|
|
|
private static Result CreateErrorResult(string errorMessage, string iconPath)
|
|
{
|
|
return new Result
|
|
{
|
|
Title = Properties.Resources.wox_plugin_calculator_calculation_failed,
|
|
SubTitle = errorMessage,
|
|
IcoPath = iconPath,
|
|
Score = 300,
|
|
};
|
|
}
|
|
}
|
|
}
|