mpv-settings icon indicating copy to clipboard operation
mpv-settings copied to clipboard

modernx silently errors and can't recover

Open JustArion opened this issue 1 year ago • 4 comments

Stacktrace & Error:

modernx: 
modernx: stack traceback:
modernx: 	mp.defaults:640: in function 'handler'
modernx: 	mp.defaults:512: in function 'call_event_handlers'
modernx: 	mp.defaults:554: in function 'dispatch_events'
modernx: 	mp.defaults:505: in function <mp.defaults:504>
modernx: 	[C]: at 0x7ff6ca0f8e30
modernx: 	[C]: at 0x7ff6ca0f7d00
modernx: Lua error: .../scripts/modernx.lua:1217: attempt to index local 'beforeLastPattern' (a nil value)

In my case, std-out & std-err has been redirected. Once the error has been thrown, the UI cannot be recovered and a restart is needed.

The fail point looks to be here

Alternate proposal: Silently fail and continue to work.

JustArion avatar May 01 '24 17:05 JustArion

thanks for letting me know. ill investigate that and see if i can cleanly resolve the issue.

Tsubajashi avatar May 06 '24 21:05 Tsubajashi

Hi again, circling back to this. I decided to give it a shot myself. I used LUA a bit back in WoW so I figured why not.

This seems to have fixed the issue, though I'll continue testing overtime through personal use.

Here's the changed function

function exec_description(args, result)
    local ret = mp.command_native_async({
        name = "subprocess",
        args = args,
        capture_stdout = true,
        capture_stderr = true
    }, function(res, val, err)
        if val and val.stdout then
            -- replace actual linebreaks with ASS linebreaks
            state.localDescriptionClick = string.gsub(val.stdout .. state.dislikes, '\n', "\\N")

            -- check if description exists, if it doesn't get rid of the extra "----------"
            local descriptionText = state.localDescriptionClick:match("\\N----------\\N(.-)\\N----------\\N")
            if (descriptionText == '' or descriptionText == '\\N') then
                state.localDescriptionClick = state.localDescriptionClick:gsub("(.*)\\N----------\\N", "%1")
            end

            -- segment localDescriptionClick parts with " - "
            local beforeLastPattern, afterLastPattern = state.localDescriptionClick:match("(.*)\\N----------\\N(.*)")
            beforeLastPattern = beforeLastPattern and beforeLastPattern:sub(1, 120) or ""
            afterLastPattern = afterLastPattern or ""

            state.videoDescription = beforeLastPattern  .. "\\N----------\\N" .. afterLastPattern:gsub("\\N", " / ")

            local startPos, endPos = state.videoDescription:find("\\N----------\\N")

            if startPos and endPos then
                state.videoDescription = string.gsub(state.videoDescription:sub(endPos + 1), "\\N----------\\N", " | ")

                state.descriptionLoaded = true
                msg.info("WEB: Loaded video description")
            end
        end
    end)
end

and a diff for it

function exec_description(args, result)
    local ret = mp.command_native_async({
        name = "subprocess",
        args = args,
        capture_stdout = true,
        capture_stderr = true
    }, function(res, val, err)
+       if val and val.stdout then
            -- replace actual linebreaks with ASS linebreaks
            state.localDescriptionClick = string.gsub(val.stdout .. state.dislikes, '\n', "\\N")

            -- check if description exists, if it doesn't get rid of the extra "----------"
            local descriptionText = state.localDescriptionClick:match("\\N----------\\N(.-)\\N----------\\N")
            if (descriptionText == '' or descriptionText == '\\N') then
                state.localDescriptionClick = state.localDescriptionClick:gsub("(.*)\\N----------\\N", "%1")
            end

            -- segment localDescriptionClick parts with " - "
            local beforeLastPattern, afterLastPattern = state.localDescriptionClick:match("(.*)\\N----------\\N(.*)")
+         beforeLastPattern = beforeLastPattern and beforeLastPattern:sub(1, 120) or ""
+         afterLastPattern = afterLastPattern or ""
+
            state.videoDescription = beforeLastPattern  .. "\\N----------\\N" .. afterLastPattern:gsub("\\N", " / ")

            local startPos, endPos = state.videoDescription:find("\\N----------\\N")
+
+         if startPos and endPos then
                state.videoDescription = string.gsub(state.videoDescription:sub(endPos + 1), "\\N----------\\N", " | ")

                state.descriptionLoaded = true
                msg.info("WEB: Loaded video description")
+         end
 +    end
    end)
end

JustArion avatar Oct 09 '24 02:10 JustArion

Hi! sorry for the late response. some people on reddit sent me DMs for a few other things, so ill add these changes when i finished some lowend-specific configs. Thank you!

Tsubajashi avatar Oct 28 '24 09:10 Tsubajashi

I got another hit on a modernx exception while watching a local file.

     modernx:
     modernx: stack traceback:
     modernx:   ...oop/apps/mpv/current/portable_config/scripts/modernx.lua:1047: in function 'checktitle'
     modernx:   ...oop/apps/mpv/current/portable_config/scripts/modernx.lua:1040: in function 'handler'
     modernx:   mp.defaults:515: in function 'call_event_handlers'
     modernx:   mp.defaults:557: in function 'dispatch_events'
     modernx:   mp.defaults:508: in function <mp.defaults:507>
     modernx:   [C]: at 0x7ff6b40f3a40
     modernx:   [C]: at 0x7ff6b40f2860
     modernx: Lua error: ...oop/apps/mpv/current/portable_config/scripts/modernx.lua:1047: bad argument #1 to 'find' (string expected, got nil)

At modernx:1047

-         if (string.find(mp.get_property("path"), "watch?")) then

+        local path = mp.get_property("path")
+        if (path == nil) then
+            path = ""
+        end
+        if (string.find(path, "watch?")) then

JustArion avatar Jun 07 '25 22:06 JustArion