Compare commits

..

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
1291fbf3dc Fix unhandled exception for sqrt(-1) in Calculator plugin by handling Complex number results
Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/fb3c68a1-171a-4418-947d-2a37617c8500

Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
2026-04-29 10:05:24 +00:00
copilot-swe-agent[bot]
169df6998e Initial plan 2026-04-29 08:51:28 +00:00
6 changed files with 22 additions and 13 deletions

View File

@@ -39,6 +39,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
[DataTestMethod]
[DataRow("test")]
[DataRow("[10,10]")] // '[10,10]' is interpreted as array by mages engine
[DataRow("sqrt(-1)")] // sqrt(-1) returns a complex number which is not supported
public void Interpret_NoResult_WhenCalled(string input)
{
// Arrange

View File

@@ -43,6 +43,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
[DataRow("10+(8*9)/0*7", "Expression contains division by zero")]
[DataRow("10+(8*9)/0x00", "Expression contains division by zero")]
[DataRow("10+(8*9)/0b0", "Expression contains division by zero")]
[DataRow("=sqrt(-1)", "Result is a complex number")]
public void ErrorResultOnInvalidKeywordQuery(string typedString, string expectedResult)
{
Query expectedQuery = new(typedString, "=");

View File

@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Numerics;
using System.Text.RegularExpressions;
using Mages.Core;
@@ -122,6 +123,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
return Properties.Resources.wox_plugin_calculator_double_array_returned;
}
if (result is Complex)
{
// Result is a complex number (e.g. sqrt(-1))
return Properties.Resources.wox_plugin_calculator_complex_number_result;
}
return result;
}
}

View File

@@ -69,6 +69,15 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Result is a complex number.
/// </summary>
public static string wox_plugin_calculator_complex_number_result {
get {
return ResourceManager.GetString("wox_plugin_calculator_complex_number_result", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copy failed, please try later.
/// </summary>

View File

@@ -158,6 +158,9 @@
<value>Ignores your system setting and returns numbers in the format '{0}'.</value>
<comment>{0} is a placeholder and will be replaced in code.</comment>
</data>
<data name="wox_plugin_calculator_complex_number_result" xml:space="preserve">
<value>Result is a complex number</value>
</data>
<data name="wox_plugin_calculator_division_by_zero" xml:space="preserve">
<value>Expression contains division by zero</value>
</data>

View File

@@ -9,7 +9,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
@@ -136,18 +135,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
var sourcePage = e.SourcePageType?.FullName ?? "<unknown>";
if (e.Exception is null)
{
Logger.LogWarning($"Navigation to '{sourcePage}' failed without an exception.");
}
else
{
Logger.LogError($"Navigation to '{sourcePage}' failed.", e.Exception);
}
e.Handled = true;
throw e.Exception;
}
private void Frame_Navigated(object sender, NavigationEventArgs e)