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

[PT Run] Calculator logs exception on some invalid queries #17320

Closed
htcfreek opened this issue Mar 28, 2022 · 8 comments
Closed

[PT Run] Calculator logs exception on some invalid queries #17320

htcfreek opened this issue Mar 28, 2022 · 8 comments
Assignees
Labels
Area-Logging Issues regarding the PowerToys logging facility Issue-Bug Something isn't working Priority-3 Bug that is low priority Product-PowerToys Run Improved app launch PT Run (Win+R) Window Resolution-Fix Committed Fix is checked in, but it might be 3-4 weeks until a release. Run-Plugin Things that relate with PowerToys Run's plugin interface

Comments

@htcfreek
Copy link
Collaborator

htcfreek commented Mar 28, 2022

https://github.com/microsoft/PowerToys/blob/main/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/Main.cs#L31-L34

This code above causes exceptions in the log file that say = or <query> is not a valid operation that can be parsed.

We should simply return List<Result>(0) if query is empty, null, whitespace, equals the action key or equals =.

@ghost ghost added the Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams label Mar 28, 2022
@htcfreek htcfreek changed the title [PT Run] Crash when on some queries [PT Run] Calculator logs exception when on some queries Mar 28, 2022
@htcfreek htcfreek changed the title [PT Run] Calculator logs exception when on some queries [PT Run] Calculator logs exception on some invalid queries Mar 28, 2022
@htcfreek
Copy link
Collaborator Author

@jaimecbernardo
I going to upload the log file later this evening.

@jaimecbernardo
Copy link
Collaborator

Sounds good 👍 Thank you

@htcfreek htcfreek added Issue-Bug Something isn't working Product-PowerToys Run Improved app launch PT Run (Win+R) Window Run-Plugin Things that relate with PowerToys Run's plugin interface labels Mar 28, 2022
@htcfreek
Copy link
Collaborator Author

htcfreek commented Mar 28, 2022

Log and the settings file:
calc-bugs.zip

PowerToys version: 0.56.2

If only action char is entered and search term is empty:

[2022-03-27 21:24:38.0161] [ERROR] [C:\a\_work\1\s\src\modules\launcher\PowerLauncher\Plugin\PluginManager.cs::215]
-------------------------- Begin exception --------------------------
Message: Exception for plugin <Calculator> when query <=>

Exception full name  : System.ArgumentNullException
Exception message    : Value cannot be null. (Parameter 'input')
Exception stack trace:
   at Microsoft.PowerToys.Run.Plugin.Calculator.CalculateHelper.InputValid(String input)
   at Microsoft.PowerToys.Run.Plugin.Calculator.Main.Query(Query query)
   at PowerLauncher.Plugin.PluginManager.<>c__DisplayClass22_0.<QueryForPlugin>b__0()
   at Wox.Infrastructure.Stopwatch.Debug(String message, Action action)
   at PowerLauncher.Plugin.PluginManager.QueryForPlugin(PluginPair pair, Query query, Boolean delayedExecution)
Exception source     : Microsoft.PowerToys.Run.Plugin.Calculator
Exception target site: Boolean InputValid(System.String)
Exception HResult    : -2147467261
-------------------------- End exception --------------------------

If input is invalid and converted to an string error message in Interpret() method:

[2022-03-27 21:48:22.9261] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.Calculator\Main.cs::64]
-------------------------- Begin exception --------------------------
Message: Exception when query for <{query}>

Exception full name  : System.FormatException
Exception message    : Input string was not in a correct format.
Exception stack trace:
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at System.Convert.ToDecimal(String value, IFormatProvider provider)
   at System.String.System.IConvertible.ToDecimal(IFormatProvider provider)
   at System.Convert.ToDecimal(Object value, IFormatProvider provider)
   at Microsoft.PowerToys.Run.Plugin.Calculator.CalculateEngine.Interpret(String input, CultureInfo cultureInfo)
   at Microsoft.PowerToys.Run.Plugin.Calculator.Main.Query(Query query)
Exception source     : System.Private.CoreLib
Exception target site: Void ThrowOverflowOrFormatException(ParsingStatus, System.TypeCode)
Exception HResult    : -2146233033
-------------------------- End exception --------------------------

Happens on invalid expressions:

[2022-03-27 21:53:58.8246] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.Calculator\Main.cs::64]
-------------------------- Begin exception --------------------------
Message: Exception when query for <{query}>

Exception full name  : Mages.Core.ParseException
Exception message    : The given source code contains errors.
Exception stack trace:
   at Mages.Core.Ast.Walkers.OperationTreeWalker.Mages.Core.Ast.IValidationContext.Report(ParseError error)
   at Mages.Core.Ast.Expressions.InvalidExpression.Validate(IValidationContext context)
   at Mages.Core.Ast.Walkers.OperationTreeWalker.Mages.Core.Ast.ITreeWalker.Visit(InvalidExpression expression)
   at Mages.Core.Ast.Expressions.InvalidExpression.Accept(ITreeWalker visitor)
   at Mages.Core.Ast.Walkers.OperationTreeWalker.Mages.Core.Ast.ITreeWalker.Visit(ArgumentsExpression expression)
   at Mages.Core.Ast.Walkers.OperationTreeWalker.Mages.Core.Ast.ITreeWalker.Visit(CallExpression expression)
   at Mages.Core.Ast.Walkers.OperationTreeWalker.Mages.Core.Ast.ITreeWalker.Visit(BlockStatement block)
   at Mages.Core.Ast.StatementExtensions.MakeRunnable(IEnumerable`1 statements)
   at Mages.Core.Engine.Interpret(String source)
   at Microsoft.PowerToys.Run.Plugin.Calculator.CalculateEngine.Interpret(String input, CultureInfo cultureInfo)
   at Microsoft.PowerToys.Run.Plugin.Calculator.Main.Query(Query query)
Exception source     : Mages.Core
Exception target site: Void Mages.Core.Ast.IValidationContext.Report(Mages.Core.ParseError)
Exception HResult    : -2146233088
-------------------------- End exception --------------------------

If query is =[10,10]:

[2022-03-27 21:55:25.3373] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.Calculator\Main.cs::64]
-------------------------- Begin exception --------------------------
Message: Exception when query for <{query}>

Exception full name  : System.InvalidCastException
Exception message    : Unable to cast object of type 'System.Double[,]' to type 'System.IConvertible'.
Exception stack trace:
   at System.Convert.ToDecimal(Object value, IFormatProvider provider)
   at Microsoft.PowerToys.Run.Plugin.Calculator.CalculateEngine.Interpret(String input, CultureInfo cultureInfo)
   at Microsoft.PowerToys.Run.Plugin.Calculator.Main.Query(Query query)
Exception source     : System.Private.CoreLib
Exception target site: System.Object ChkCast_Helper(Void*, System.Object)
Exception HResult    : -2147467262
-------------------------- End exception --------------------------

Happens if result is to large for the decimal type:

[2022-03-27 23:23:07.3322] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.Calculator\Main.cs::64]
-------------------------- Begin exception --------------------------
Message: Exception when query for <{query}>

Exception full name  : System.OverflowException
Exception message    : Value was either too large or too small for a Decimal.
Exception stack trace:
   at System.Number.ThrowOverflowException(TypeCode type)
   at System.Decimal.DecCalc.VarDecFromR8(Double input, DecCalc& result)
   at System.Double.System.IConvertible.ToDecimal(IFormatProvider provider)
   at Microsoft.PowerToys.Run.Plugin.Calculator.CalculateEngine.Interpret(String input, CultureInfo cultureInfo)
   at Microsoft.PowerToys.Run.Plugin.Calculator.Main.Query(Query query)
Exception source     : System.Private.CoreLib
Exception target site: Void ThrowOverflowException(System.TypeCode)
Exception HResult    : -2146233066
-------------------------- End exception --------------------------

@htcfreek
Copy link
Collaborator Author

htcfreek commented Mar 29, 2022

@jaimecbernardo
For easier debugging we should fix log command to show the real query:

Exception when query for <{query}>

@jaimecbernardo jaimecbernardo added Priority-3 Bug that is low priority and removed Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Mar 29, 2022
@jaimecbernardo
Copy link
Collaborator

Nice to have. Doesn't impact the user much, but would help in debugging in the future.

@jaimecbernardo
Copy link
Collaborator

Perhaps an actual error result when Calculator is called with keyword would be nice as well.

@Jay-o-Way Jay-o-Way added the Area-Logging Issues regarding the PowerToys logging facility label Apr 24, 2022
@htcfreek htcfreek self-assigned this May 4, 2022
@htcfreek
Copy link
Collaborator Author

htcfreek commented May 7, 2022

Perhaps an actual error result when Calculator is called with keyword would be nice as well.

Should this show the error message from exception in subtitle?

@htcfreek htcfreek added the Status-In progress This issue or work-item is under development label May 8, 2022
@jaimecbernardo jaimecbernardo removed the Status-In progress This issue or work-item is under development label Jun 2, 2022
@jaimecbernardo jaimecbernardo added the Resolution-Fix Committed Fix is checked in, but it might be 3-4 weeks until a release. label Jun 2, 2022
@htcfreek
Copy link
Collaborator Author

Released with v0.59.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Logging Issues regarding the PowerToys logging facility Issue-Bug Something isn't working Priority-3 Bug that is low priority Product-PowerToys Run Improved app launch PT Run (Win+R) Window Resolution-Fix Committed Fix is checked in, but it might be 3-4 weeks until a release. Run-Plugin Things that relate with PowerToys Run's plugin interface
Projects
None yet
Development

No branches or pull requests

3 participants