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
76 stars 6 forks source link

Unexpected end of input error #38

Closed Slugger closed 2 years ago

Slugger commented 4 years ago

Describe the bug After every event handler function call, I see the following error in the emby log:

2020-06-21 06:47:02.068 Error Emby ScripterX: Error invoking function '_onPlaybackStopped' on package with installationId '679b7e32-79be-4330-b8c7-6dfdf992f740' failed: Jint.Parser.ParserException: Line 0: Unexpected end of input
at Jint.Runtime.Interop.MethodInfoFunctionInstance.Invoke(MethodInfo[] methodInfos, JsValue thisObject, JsValue[] jsArguments)
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)

All of my event handlers are single line functions calling JsonPost(). My webhooks are called, but I do see this error logged after every invocation of my functions.

To Reproduce Steps to reproduce the behavior:

  1. Install a package with event handlers
  2. Trigger any of the events
  3. See error in emby log

Expected behavior No error or if this isn't an error/can be ignored then probably suppress it or log it at debug/trace.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

AnthonyMusgrove commented 4 years ago

This one is interesting mate - could you send me a copy of your Package.js so I can find out why it's spitting this error out for you. You can email it to me if you like - anthony@emby-scripterx.info

Slugger commented 4 years ago

I'll just paste it here, there's nothing secretive about it. At least not yet as I'm still experimenting with ScripterX, etc. :)

var baseUrl = ScripterX.Config.Get('embyInsightsUrl').value;
var log = ScripterX.Log;
var web = ScripterX.Web;

function _package_init() {
    log.Info('EmbyInsights initialized with base URL: ' + baseUrl);
}

function _onPlaybackStart(ctx) {
    log.Debug('PlaybackStart:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/playbackStart', ctx.allTokens().toString());
}

function _onPlaybackStopped(ctx) {
    log.Debug('PlaybackStopped:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/playbackStopped', ctx.allTokens().toString());
}

function _onAuthenticationSuccess(ctx) {
    log.Debug('AuthSuccess:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/authenticationSuccess', ctx.allTokens().toString());
}

function _onAuthenticationFailed(ctx) {
    log.Debug('AuthFailed:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/authenticationFailed', ctx.allTokens().toString());
}

function _onUserPasswordChanged(ctx) {
    log.Debug('PasswordChanged:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/userPasswordChanged', ctx.allTokens().toString());
}

function _onUserConfigurationUpdated(ctx) {
    log.Debug('UserCfgUpdated:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/userConfigurationUpdated', ctx.allTokens().toString());
}

function _onUserCreated(ctx) {
    log.Debug('UserCreated:\n' + ctx.allTokens().toString());
    web.JsonPost(baseUrl + 'event/userCreated', ctx.allTokens().toString());
}
AnthonyMusgrove commented 4 years ago

Hi mate, thank you. I've tested the script and on my end its working awesomely;

2020-06-22 17:34:19.898 Debug Emby ScripterX: 8b91c4d0-66f2-47c8-9471-ae9c741d6b6f: AuthFailed: { "%server.name%": "MediusDev2", "%server.port.local.http%": "8096", "%server.port.local.https%": "8920", "%server.port.public.http%": "8096", "%server.port.public.https%": "8920", "%server.version%": "4.4.3.0", "%server.platform.os%": "Win32NT", "%server.platform.osver%": "6.2.9200.0 ", "%server.platform.uptime%": "1d 21h 50m 21s ", "%scripterx.version%": "3.0.4.7", "%scripterx.version.major%": "3", "%scripterx.version.minor%": "0", "%scripterx.version.revision%": "7", "%scripterx.version.build%": "4", "%username%": "Anthony", "%user.id%": "0", "%device.id%": "1cd496ba-97bf-46b6-aeb7-b7f64b0a87fe", "%device.name%": "Firefox", "%password%": "dsghdfghdfgh", "%device.app%": "Emby Web", "%device.app.version%": "4.4.3.0", "%device.remote.ipaddress%": "::1" } 2020-06-22 17:34:19.906 Error Emby ScripterX: Error invoking function '_onAuthenticationFailed' on package with installationId '8b91c4d0-66f2-47c8-9471-ae9c741d6b6f' failed: System.UriFormatException: Invalid URI: The format of the URI could not be determined.

I wonder if its some type of weird encoding in your script file?

AnthonyMusgrove commented 4 years ago

I just thought of something too regarding allTokens(), I might put a filter argument on it so you can specify which tokens to include, what do you think? like allTokens() will work as normal, but allTokens("%user.id%,%device.app%") would only include them two? (incase you don't want to send specific tokens over)

AnthonyMusgrove commented 4 years ago

or even allTokensIn("comma,delimited,list,of,tokens,to,include")

Slugger commented 4 years ago

I like the extra filtering options idea for allTokens(). Did some testing on the file encoding and that doesn't seem to matter. Windows or Unix line endings, doesn't matter, same result. It's odd that it's complaining about "Line 0" after the function has completed successfully (reminder, the functions are running to completion as expected).