feline.nvim icon indicating copy to clipboard operation
feline.nvim copied to clipboard

[Bug] E5108: Error executing lua ... E539: Illegal character < > | Strings Ending With %%

Open orlandosh opened this issue 2 years ago • 3 comments

Neovim version

NVIM v0.8.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/builddir/build/BUILD/neovim-0.8.0/redhat-linux-build/cmake.config -I/builddir/build/BUILD/neovim-0.8.0/src -I/usr/include -I/usr/include/luajit-2.1 -I/builddir/build/BUILD/neovim-0.8.0/redhat-linux-build/src/nvim/auto -I/builddir/build/BUILD/neovim-0.8.0/redhat-linux-build/include

Compiled by mockbuild@koji

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Describe the bug I get this error message, and feline crashes

E5108: Error executing lua ...e/pack/packer/start/feline.nvim/lua/feline/generator.lua:517: E539: Illegal character < >                                                                                                                       
stack traceback:                                                                                                                                                                                                                              
        [C]: in function 'nvim_eval_statusline'                                                                                                                                                                                               
        ...e/pack/packer/start/feline.nvim/lua/feline/generator.lua:517: in function 'get_component_width'                                                                                                                                    
        ...e/pack/packer/start/feline.nvim/lua/feline/generator.lua:609: in function <...e/pack/packer/start/feline.nvim/lua/feline/generator.lua:526>  

To Reproduce Steps to reproduce the behavior:

  1. Open nvim
  2. Make sure you have a component that returns a string ending with %%
  3. See the error message

Provide modified minimal_init.lua My feline configuration can be found here: https://github.com/orlandosh/dotfiles/blob/main/neovim/lua/plugins/feline.lua https://github.com/orlandosh/dotfiles/tree/main/neovim/lua/plugins/feline (it's a folder)

Additional context I've also tried to reinstall everything from scratch and update every plugin, it's expected since I haven't updated neovim and feline in a while.

Where the bug is After investigating, I found that the bug happens whenever the component returns a string ending in %%. This didn't happen in past versions of feline or neovim. I'm not sure which program is causing this. You can see the comment here: https://github.com/feline-nvim/feline.nvim/issues/318#issuecomment-1265709229

orlandosh avatar Oct 03 '22 14:10 orlandosh

Can you try to single out a specific component that gives this error

famiu avatar Oct 03 '22 16:10 famiu

Yes, it's file_name

local fe_vi_mode = require("feline.providers.vi_mode")
local fe_file = require("feline.providers.file")
local fe_git = require("feline.providers.git")
local fe_cursor = require("feline.providers.cursor")

local file_name = {
	provider = function(component)
		local file_name, _ = fe_file.file_info(component, { type = "unique" })
		local pos = fe_cursor.position(component, {}):gsub("%s+", "")
		local percent = fe_cursor.line_percentage():lower():gsub("%s+", "")

		if percent:find("bot") then
			percent = "100%%"
		elseif percent:find("top") then
			percent = "0%%"
		end

		percent = percent:format("%-4s", percent) .. "%%"
		local pos_percent = string.format("%-16s", pos .. ":" .. percent)

		local icon_str, icon_color = require("nvim-web-devicons").get_icon_colors_by_filetype(
			vim.bo.filetype,
			{ default = true }
		)

		local icon = { str = icon_str }
		icon.hl = { fg = icon_color }

		return file_name .. ":" .. pos_percent, icon
	end,
	left_sep = " ",
}

Edit: after further debugging, I found that returning a string in this format is what triggers the bug feline.lua:31:6:21% And after investigating, adding the line pos_percent = pos_percent:gsub("%%", "") The error is gone, meaning the bug is somewhere within feline that does not accept strings ending with %%.

orlandosh avatar Oct 03 '22 16:10 orlandosh

Just a comment to notify that I've edited both the post and the comment with new information.

orlandosh avatar Oct 03 '22 18:10 orlandosh

Yes, it's file_name

local fe_vi_mode = require("feline.providers.vi_mode")
local fe_file = require("feline.providers.file")
local fe_git = require("feline.providers.git")
local fe_cursor = require("feline.providers.cursor")

local file_name = {
	provider = function(component)
		local file_name, _ = fe_file.file_info(component, { type = "unique" })
		local pos = fe_cursor.position(component, {}):gsub("%s+", "")
		local percent = fe_cursor.line_percentage():lower():gsub("%s+", "")

		if percent:find("bot") then
			percent = "100%%"
		elseif percent:find("top") then
			percent = "0%%"
		end

		percent = percent:format("%-4s", percent) .. "%%"
		local pos_percent = string.format("%-16s", pos .. ":" .. percent)

		local icon_str, icon_color = require("nvim-web-devicons").get_icon_colors_by_filetype(
			vim.bo.filetype,
			{ default = true }
		)

		local icon = { str = icon_str }
		icon.hl = { fg = icon_color }

		return file_name .. ":" .. pos_percent, icon
	end,
	left_sep = " ",
}

Edit: after further debugging, I found that returning a string in this format is what triggers the bug feline.lua:31:6:21% And after investigating, adding the line pos_percent = pos_percent:gsub("%%", "") The error is gone, meaning the bug is somewhere within feline that does not accept strings ending with %%.

No, the issue is that the component ends with 3 % characters. When you use %% in gsub, the first % character is actually used to escape the second one since Lua uses % as the escape character for patterns. So gsub in this case actually replaces every instance of a single % character instead of %%. As for the component that's causing the error, it's because it's ending with 3 % characters, which causes Neovim to use the first % to escape the second one, but the third one has no characters after it, which causes an error since Neovim uses % in statusline to denote the start of a statusline item. Simply put, just remove the last % char from the component and it should be fixed.

famiu avatar Oct 05 '22 10:10 famiu