trunk-io / neovim-trunk

The official Trunk Check Plugin for Neovim
https://docs.trunk.io/check/ide-integration/neovim-plugin
MIT License
21 stars 3 forks source link

Error when .trunk/logs (config.out_file) doesn't exist #16

Closed docwhat closed 7 months ago

docwhat commented 7 months ago

If the config.out_file's directory doesn't exist, then the plugin throws an error when trying to write the log file.

The code

The code is lua/log.lua:151

-- Output to log file
if config.use_file then
    local fp = io.open(config.out_file, "a")
    local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg)
    fp:write(str) -- <-- error thrown here
    fp:close()
end

The error message

Failed to run `config` for lsp-zero.nvim

.../.local/share/nvim/lazy/neovim-trunk/lua/log.lua:151: attempt to index local 'fp' (a nil value)

# stacktrace:
  - /neovim-trunk/lua/log.lua:151 _in_ **info**
  - /neovim-trunk/lua/trunk.lua:28
  - ...

The workarounds

TylerJang27 commented 7 months ago

Thanks for reporting this! It should be fixed in the latest release v0.1.3. Please let us know if you encounter any other issues