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

modernx silently errors and can't recover #40

Open
JustArion opened this issue May 1, 2024 · 3 comments
Open

modernx silently errors and can't recover #40

JustArion opened this issue May 1, 2024 · 3 comments

Comments

@JustArion
Copy link

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.

@Tsubajashi
Copy link
Owner

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

@JustArion
Copy link
Author

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

@Tsubajashi
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants