Skip to content

Error in Autocommands: "bad argument #2 to 'format' (number expected, got nil)" after lazy.nvim shows its UI at startup #19

Description

@achadwick

Observed error

The current git head of bg.nvim, 85da2c6, produces the following error after lazy.nvim installs anything, but not at other times. I am using stock configs for both, in nvim v0.11.6 with LuaJIT 2.1.1761786044 from Debian testing.

Error detected while processing UIEnter Autocommands for "*":
Error executing lua callback: /tmp/bg_nvim/.local/share/nvim/lazy/bg.nvim/plugin/bg.lua:30: bad argument #2 to 'format' (number expected, got nil)
stack traceback:
        [C]: in function 'format'
        /tmp/bg_nvim/.local/share/nvim/lazy/bg.nvim/plugin/bg.lua:30: in function </tmp/bg_nvim/.local/share/nvim/lazy/bg.nvim/plugin/bg.lua:21>

Lazy.nvim is a plugin manager that shows a little UI on startup if it needs to download any plugins. I know that Lazy sets up some sort of colour scheme for its UI when it runs at nvim startup, and I suspect an incompleteness in that scheme or how Lazy uses it causes issues for bg.nvim.

Steps to reproduce

Set up a test environment

mkdir -vp /tmp/bg_nvim
cd /tmp/bg_nvim/
cat > init.lua

Paste the content below

-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

-- Pull in bg.nvim and something else
require("lazy").setup({
	spec = {
		{ "goncaloalves/neovim-plugin-hello-world", lazy=true, },
		{ "nvim-mini/mini.misc", lazy=true, },
		{ "typicode/bg.nvim", lazy=false, },
	},
})

-- Say hi if we get to the end
vim.notify("hello, world")

To exercise the environment and show the error:

cd /tmp/bg_nvim
HOME=`pwd` nvim  -u ./init.lua
rm -fr .cache .config .local     # optional, purges earlier state if needed

The error will happen

  1. On the first run

  2. Not on subsequent runs if Lazy has nothing to do (does not show its UI at startup)

  3. On subsequent runs if Lazy.nvim has anything to do (shows its UI at startup)

    • To achieve this state, run :Lazy and cursor down to another plugin line, e.g. mini.miscs
    • Press x to remove the plugin
    • Quit and restart neovim in this state
    • Run nvim again

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions