Skip to content

Plugin using RunInteractiveShell crashes Micro #4023

@usfbih8u

Description

@usfbih8u

Description

Micro crashes in onBufferOpen(), onBufPaneOpen(), postinit(), preinit(), and init() if you attempt to run an interactive shell (RunInteractiveShell()) before signal setup is complete (cmd/micro/micro.go:447).

-- USE COMMAND: micro -filetype myuniquespecialfiletype
function postinit()
    local bp = micro.CurPane()
    if bp then
        local ft = bp.Buf.Settings["filetype"]
        if ft == "myuniquespecialfiletype" then
        -- This was a call to bp:HandleCommand() with my plugin,
        -- but the crash was actually caused by the shell.RunInteractiveShell() 
        -- call.
        -- bp:HandleCommand("myplugin")
        shell.RunInteractiveShell("fzf-for-example", true, true)              
        bp:QuitAll()
    end
end

Crash:

Plugin test: os/signal: Notify using nil channel
    stack traceback:
            [G]: in function 'HandleCommand'
            main:17: in main chunk
            [G]: ?     

I attempted to use AfterFunc() from the time package, but it triggered a different type of crash.

function postinit()
    local gotime = import("time")
    gotime.AfterFunc(4 * gotime.Second, function()
        local bp = micro.CurPane()
        if bp then
            local ft = bp.Buf.Settings["filetype"]
            if ft == "myuniquespecialfiletype" then
                shell.RunInteractiveShell("fzf-for-example", true, true)              
                bp:QuitAll()
            end
        end
    end)
end
Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:262 (0x472b19)
runtime/panic.go:261 (0x472ae9)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:490 (0x94bb41)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:481 (0x94ba50)
internal/runtime/atomic/types.go:194 (0x43bc6b)
runtime/asm_amd64.s:1700 (0x478de1)

Using After() from micro's LuaTable resolved the issue (this presumably waits until all setup is complete).

Environment

  • Version: 2.0.15 release
  • OS: Linux
  • Terminal: all

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions