jonathanmorris180 / salesforce.nvim

A Salesforce plugin for Neovim.
MIT License
20 stars 5 forks source link

Error executing lua callback #40

Open mauroapo opened 2 weeks ago

mauroapo commented 2 weeks ago

Description

Steps to reproduce

  1. I opened nvim in my Apex Class, selected the default org and I got this error after a SalesforcePushToOrg command
  2. Then I saw the error below
  3. Error ` Error executing Lua callback: ...Local\nvim-data\plugged\plenary.nvim/lua/plenary/job.lua:406: Failed to spawn process: { _additional_on_exit_callbacks = {}, _shutdown_check = <userdata 1>, _stderr_results = {}, _stdout_results = {}, _user_on_exit = <function 1>, _user_on_stderr = <function 2>, _user_on_stdout = <function 3>, args = { "project", "deploy", "start", "--json", "-o", "mauro.apo123@resourceful-panda-v0tc3s.com", "-d", "C:\Users\Acer\Documents\Projetos\Salesforce\ResourcefulPanda\force-app\main\default\classes\WarehouseCalloutService.cls" }, command = "sf", enable_handlers = true, enable_recording = true, interactive = true, pid = "ENOENT: no such file or directory", stderr = <userdata 2>, stdin = <userdata 3>, stdout = <userdata 4>, user_data = {}, = <1>{ __index = , _create_uv_options = , _execute = , _pipes_are_closed = , _prepare_pipes = , _reset = , _shutdown = , _stop = , add_on_exit_callback = , after = , after_failure = , after_success = , and_then = , and_then_on_failure = , and_then_on_failure_wrap = , and_then_on_success = , and_then_on_success_wrap = , and_then_wrap = , chain = , chain_status = , co_wait = , is_job = , is_running = , join = , new = , pid = , result = , send = , shutdown = , start = , stderr_result = , sync = , wait = } } stack traceback: ...Local\nvim-data\plugged\plenary.nvim/lua/plenary/job.lua:406: in function '_execute' ...Local\nvim-data\plugged\plenary.nvim/lua/plenary/job.lua:449: in function 'start' [string ":lua"]:27: in function 'debug_job' stack traceback: [C]: in function 'error' ...Local\nvim-data\plugged\plenary.nvim/lua/plenary/job.lua:406: in function '_execute' ...Local\nvim-data\plugged\plenary.nvim/lua/plenary/job.lua:449: in function 'start' [string ":lua"]:27: in function 'debug_job' ## Expected behavior

    Expected the class to be pushed to the org

    Environment

    • NVIM v0.10.0
    • salesforce.nvim version: [e.g. latest]
    • Plugin clash: [e.g. Telescope float window / lsp diagnostic]

    Other comments

    I did the command below inside of the same terminal I was executing the :SalesforcePushToOrg command

    :terminal sf project deploy start --json -o mauro.apo123@resourceful-panda-v0tc3s.com -d C:\Users\Acer\Documents\Projetos\Salesforce\ResourcefulPanda\force-app\main\default\classes\WarehouseCalloutService.cls

    and it worked fine

    jonathanmorris180 commented 2 weeks ago

    Hi @mauroapo, it looks like the issue is occurring because the file path isn't getting resolved correctly (it seems double backslashes are getting added). It's looking for C:\\Users\\Acer\\Documents\\Projetos\\Salesforce\\ResourcefulPanda\\force-app\\main\\default\\classes\\WarehouseCalloutService.cls, which results in ENOENT: no such file or directory. The code that retrieves the file path is here. Could you please run the following in your Neovim command line and let me know what they print?

    :lua print(vim.fn.expand("%:p"))
    :lua print(vim.fs.normalize(vim.fn.expand("%:p")))
    mauroapo commented 2 weeks ago

    I believe it has to have double backslashes on windows

    I added the following code to my init file to debug but the same problem occurs

    " Lua block for debugging job
    lua << EOF
    local Job = require'plenary.job'
    
    local function debug_job()
        -- Create and start the job
        Job:new({
            command = 'sf',
            args = { 'project', 'deploy', 'start', '--json', '-o', 'mauro.apo123@resourceful-panda-v0tc3s.com', '-d', 'C:\\Users\\Acer\\Documents\\Projetos\\Salesforce\\ResourcefulPanda\\force-app\\main\\default\\classes\\WarehouseCalloutService.cls' },
            on_exit = function(j, return_val)
                -- Log return value and result
                print("Return Value: ", return_val)
                print("Result: ", table.concat(j:result(), "\n"))
            end,
            on_stderr = function(_, data)
                -- Log any stderr output
                print("Error: ", data)
            end,
            on_stdout = function(_, data)
                -- Log any stdout output
                print("Output: ", data)
            end,
        }):start()
    end
    
    vim.api.nvim_create_user_command('DebugJob', function()
        debug_job()
    end, {})
    EOF
    

    First command response: image

    Second command response: image

    jonathanmorris180 commented 2 weeks ago

    @mauroapo Can you please try changing the sf_executable to sf.cmd in your configuration of salesforce.nvim as proposed here? I believe this may be the fix (theoretically it should detect the OS and update the executable accordingly, but I think this may not be working as expected).

    jonathanmorris180 commented 1 week ago

    @mauroapo Did you try the fix above?

    mauroapo commented 1 week ago

    Hello, I'm sorry for the delay. It has been a busy week. I did the change as requested but the issue persist. Here are the steps I did:

    1 - opened the salesforce/config.lua file 2 - change the sf_executable to sf.cmd 3 - opened the salesforce file I want to push with nvim 4 - did the SalesforcePushToOrgCommand

    image

    Then I tried changing the executable variable inside the lua files. And it worked as expected.

    image

    I added all the changes to https://github.com/mauroapo/salesforce.nvim/commit/5fcd265a165c9c916feb709275a0f4252ed59de9 for you to check. In it you'll see the changes in the config.lua, that didn't solve the issue, and the changes for file_manager.lua and diff.lua, that solved the issue. I can move the if from config.lua to all files if you think that's the way to go. Something curious though is that the commands in org_manager.lua didn't present the same issue and have always worked properly

    jonathanmorris180 commented 1 week ago

    Thanks for that info @mauroapo. It looks like there's a bug in the code that results in the executable not being recognized because of the order in which things get loaded on startup. Can you please let me know what prints in your terminal with the following command? I think I have a good way to solve this issue, but I want to check that it will be compatible with Windows first:

    :lua print(vim.fn.fnamemodify(vim.fn.exepath("sf"), ":t"))

    Thanks for helping to debug this!

    mauroapo commented 1 week ago

    Hello @jonathanmorris180, after executing the command this was the return: image I hope it helps :)

    jonathanmorris180 commented 1 week ago

    Hi @mauroapo, I have added a fix for this in #41. Can you please pull down the fix/issue-40 branch and try it out? You would have to specify the branch in your plugin manager and possibly reinstall the plugin using that branch. After you have confirmed that it's working for you, I'll merge it into main.

    jonathanmorris180 commented 1 week ago

    Hi @mauroapo, were you able to try out the fix from #41?

    mauroapo commented 1 day ago

    @jonathanmorris180 just tested the changes. It is working well