bug: Assertion failed in function "relative_path"
Neovim version (nvim -v)
NVIM v0.10.0-dev-3085+gb024643ca Build type: RelWithDebInfo LuaJIT 2.1.1713484068
Operating system/version
Windows 11
Add the debug logs
- [X] I have set
log_level = vim.log.levels.DEBUGand pasted the log contents below.
Log file
21:37:34[DEBUG] Running formatters on C:\Users\chosun\AppData\Local\nvim\lua\custom\plugins\conform.lua: { "stylua" } 21:37:34[INFO] Run stylua on C:\Users\chosun\AppData\Local\nvim\lua\custom\plugins\conform.lua 21:37:34[TRACE] Input lines: { "return {", " { -- Autoformat", " 'stevearc/conform.nvim',", " opts = {", " notify_on_error = true,", " log_level = vim.log.levels.TRACE,", " format_on_save = function(bufnr)", " -- Disable "format_on_save lsp_fallback" for languages that don't", " -- have a well standardized coding style. You can add additional", " -- languages here or re-enable it for the disabled ones.", " local disable_filetypes = { c = true, cpp = true }", " return {", " async = true,", " lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],", " }", " end,", " -- NOTE: see :help conform-formatters for adding options here", " formatters_by_ft = {", " lua = { 'stylua' },", " -- Conform can also run multiple formatters sequentially", " python = { 'black' },", " -- go = { 'gofmt' },", " rust = { 'rustfmt' },", " -- markdown = { 'mdformat' },", " -- yaml = { 'yamlfmt' },", " javascript = { 'prettierd' },", " --", " -- You can use a sub-list to tell conform to run until a formatter", " -- is found.", " -- javascript = { { 'prettierd', 'prettier' } },", " },", " },", " },", "}" }
Describe the bug
On Windows, I get this error every time I save the file, and none of my formatting is applied:
Error executing lua callback: ...ata\Local\nvim-data\lazy\conform.nvim/lua/conform/fs.lua:76: assertion failed!
stack traceback:
[C]: in function 'assert'
...ata\Local\nvim-data\lazy\conform.nvim/lua/conform/fs.lua:76: in function 'relative_path'
...Local\nvim-data\lazy\conform.nvim/lua/conform/runner.lua:40: in function 'build_cmd'
...Local\nvim-data\lazy\conform.nvim/lua/conform/runner.lua:291: in function 'run_formatter'
...Local\nvim-data\lazy\conform.nvim/lua/conform/runner.lua:633: in function 'format_lines_sync'
...Local\nvim-data\lazy\conform.nvim/lua/conform/runner.lua:589: in function 'format_sync'
...a\Local\nvim-data\lazy\conform.nvim/lua/conform/init.lua:451: in function 'format'
...a\Local\nvim-data\lazy\conform.nvim/lua/conform/init.lua:104: in function <...a\Local\nvim-data\lazy\
What is the severity of this bug?
breaking (some functionality is broken)
Steps To Reproduce
No matter what file I open, when I save i get the reported error, and no formatting is done.
Expected Behavior
I expect there to be no error, and for formatting to be applied if applicable.
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,
-- add your config here
})
end,
},
-- add any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here
Additional context
This problem started around 4 days ago, probably with the introduction of new relative path logic.
UPDATE: My machine has multiple storage drives.
I'm having the same problem on Windows 10.
The issue seems to me to be that when calculating relative path, if the two paths are not on the same drive, the loop will never exit. In the end, the failing assertion will run into vim.fn.dirname('C:/') ~= 'C:/', for example.
@billuo I think that sounds right, the file I'm editing is on my F drive while neovim is on my C drive.
Fixed. Thanks for the report!