AnthonyMusgrove / Emby-ScripterX

Run custom external application or script (batch/bash/powershell/php/python/node.js/custom) on various events within the Emby Server.
https://emby-scripterx.com
78 stars 6 forks source link

_onAuthenticationSuccess() does not execute #43

Closed Slugger closed 3 years ago

Slugger commented 4 years ago

Describe the bug The event handler does not execute and throws a stacktrace.

To Reproduce Steps to reproduce the behavior:

  1. Install a package with this event handler
  2. Trigger the event

Expected behavior The event handler is called and executed as expected.

Additional context

2020-06-29 04:30:04.603 Error Emby ScripterX: Error invoking function '_onAuthenticationSuccess' on package with installationId '679b7e32-79be-4330-b8c7-6dfdf992f740' failed: System.ArgumentException: Can not add property %server.name% to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.
at Jint.Runtime.Interop.MethodInfoFunctionInstance.Invoke(MethodInfo[] methodInfos, JsValue thisObject, JsValue[] jsArguments)
at Jint.Runtime.ExpressionInterpreter.EvaluateCallExpression(CallExpression callExpression)
at Jint.Runtime.ExpressionInterpreter.EvaluateMemberExpression(MemberExpression memberExpression)
at Jint.Runtime.ExpressionInterpreter.EvaluateCallExpression(CallExpression callExpression)
at Jint.Runtime.ExpressionInterpreter.EvaluateBinaryExpression(BinaryExpression expression)
at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at Jint.Runtime.ExpressionInterpreter.EvaluateCallExpression(CallExpression callExpression)
at Jint.Runtime.StatementInterpreter.ExecuteExpressionStatement(ExpressionStatement expressionStatement)
at Jint.Engine.ExecuteStatement(Statement statement)
at Jint.Runtime.StatementInterpreter.ExecuteStatementList(IEnumerable`1 statementList)
at Jint.Engine.ExecuteStatement(Statement statement)
at Jint.Native.Function.ScriptFunctionInstance.Call(JsValue thisArg, JsValue[] arguments)
at EmbyScripterX.Packages.Package.invokeFunction(String function, Object[] param_objects)
AnthonyMusgrove commented 3 years ago

Thank you so much @Slugger for reporting this issue - my apologies for the very late response. I've rectified this issue and this event action will now work as expected again.

The issue was to do with %server.name% trying to be added to the event context (one from the local AuthOK, and one from the global tokens), I've renamed the local AuthOK %server.name% to %user.server.name%

Kindest regards, Anthony