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

bug: Uncaught error on when running "injected" formatter on a filetype with no treesitter parser #503

Open
1 task done
tobyvin opened this issue Jul 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@tobyvin
Copy link

tobyvin commented Jul 26, 2024

Neovim version (nvim -v)

0.10.0

Operating system/version

Linux 6.10.0-arch1-2 (Arch Linux)

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

Log file

15:05:41[DEBUG] Running formatters on : { "injected" }
15:05:41[INFO] Run injected on 
15:05:41[ERROR] error formatting log line: 'nil' args {
  n = 0
}

Describe the bug

When running the "injected" formatter on a filetype that does not have have a treesitter installed, the following error is thrown:

Error executing vim.schedule lua callback: vim/_editor.lua:0: Invalid 'str': Expected Lua string
stack traceback:
        [C]: in function 'nvim_err_writeln'
        vim/_editor.lua: in function 'notify'
        ...e/tobyv/.repro/plugins/conform.nvim/lua/conform/init.lua:18: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

From what I can tell, the issue is the callback on formatters/injected.lua#L151 is passing a string, but it's expecting a Conform.Error object. Also, due to where the error is, notify_on_error = false has no effect.

I did notice the type definition for the format function specifies a string|nil, although from what I can tell, the injected formatter is the only lua based formatter that is passing an error value directly to the callback. So I suspect the type definition should be changed.

I'd be happy to submit a PR if you want. If so, I would need to know how you want to handle actually throwing the error there, as I could see some value in handling a missing language parser differently than an actual formatter error.

Thanks for providing a super useful tool!

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. nvim -u repro.lua
  2. enter cmd mode and run lua require("conform").format()

Expected Behavior

Either no-op or show the error via vim.notify.

Minimal example file

No response

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        formatters_by_ft = {
            ["*"] = { "injected" },
        },
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

No response

@tobyvin tobyvin added the bug Something isn't working label Jul 26, 2024
Ydot19 added a commit to Ydot19/config that referenced this issue Oct 16, 2024
- Removed neotree due to not handling large directories/mono-repos
- Set conform to v6.x until
stevearc/conform.nvim#503 is resolved
- Add telescope file broswer
- Add quickfix preview
- Re-introduce oil.nvim for the ~vibes~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant