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

sqlite.lua doesn't seem to work with this. #4

Open
fireboy1919 opened this issue Mar 10, 2022 · 8 comments
Open

sqlite.lua doesn't seem to work with this. #4

fireboy1919 opened this issue Mar 10, 2022 · 8 comments

Comments

@fireboy1919
Copy link

fireboy1919 commented Mar 10, 2022

NVIM v0.6.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Latest version of all the lua libraries.

E5108: Error executing lua ...m/site/pack/packer/start/sqlite.lua/lua/sqlite/utils.lua:252: loop or previous error loading module 'sqlite.tbl'
stack traceback:
        [C]: in function 'require'
        ...m/site/pack/packer/start/sqlite.lua/lua/sqlite/utils.lua:252: in function '__index'
        ...nvim/site/pack/packer/start/sqlite.lua/lua/sqlite/db.lua:637: in function 'tbl'
        ...history.nvim/lua/telescope/_extensions/smart_history.lua:34: in function 'init'
        ...r/start/telescope.nvim/lua/telescope/actions/history.lua:76: in function 'handler'
        ...ker/start/telescope.nvim/lua/telescope/actions/state.lua:47: in function 'get_current_history'
        ...cker/start/telescope.nvim/lua/telescope/actions/init.lua:184: in function <...cker/start/telescope.nvim/lua/telescope/actions/init.lua:183>
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:23: in function 'key_func'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:236: in function 'execute_keymap'

This is my reduced packer config:

require('packer').startup(function(use)
  -- My plugins here
  use 'wbthomason/packer.nvim'
  use 'nvim-telescope/telescope.nvim'

  use {
    "nvim-telescope/telescope-smart-history.nvim",
    config = function()
      require"telescope".load_extension("smart_history")
    end,
    requires = {"tami5/sqlite.lua"}
  }

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

Telescope setup:

require("telescope").setup {
  defaults = {
    wrap_results = true,
    history = {
      path = '~/.local/share/nvim/databases/telescope_history.sqlite3',
      limit = 100
    }
  }
}
@kkharji
Copy link
Member

kkharji commented Mar 10, 2022

🤔 that's odd, couldn't reproduce. I'm on NVIM v0.7.0-dev

@fireboy1919
Copy link
Author

So...I was able to track it down.

If you manage to in some way install telescope-smart-history and have not yet gotten sqlite.lua working (if, for example, you don't have the sqlite binaries on your machine when you first install it), then telescope-smart-history will create a garbage sqlite file.

And from that point on, it will fail even if you get your machine set up as intended until you delete that garbage file.

@kkharji
Copy link
Member

kkharji commented Mar 11, 2022

Well done @fireboy1919, Interesting bug, any ideas to prevent it?

@fireboy1919
Copy link
Author

BTW, I also produced this error with telescope-frecency

This seems like something that should actually be built into sqlite.lua, but I can think of two defensive approaches that would prevent this bug:

  1. If the initial attempt to create a sqlite instance fails, then the library could aggressively clean up after itself.

This would unfortunately mean specifically keeping track of the case when you are first creating a file rather than entirely treating the database API as handling all file operations itself, but even so, it's not going to affect performance very much so that's probably okay.

  1. sqlite.lua could have some sort of "clobber" option that detects if the database doesn't load and can prompt the user to recreate the database if it fails to load.

Alternatively, this problem probably doesn't need to be actually prevented since it's easy for a user to fix. It just needs to be detected. If sqlite fails to load, there should be a better error message logged somewhere informing the user that sqlite.lua couldn't load the extension.

@thuan1412
Copy link

Hi @fireboy1919, I got the same error, but do not know the path of the garbage file. Could you tell me its path?

@samuelabreu
Copy link

In my case i needed to install libsqlite3-dev on ubuntu.

To check if its ok run inside nvim after install sqlite.lua:

:lua require "sqlite.tbl"

@fireboy1919
Copy link
Author

fireboy1919 commented Jun 2, 2022

I specified the path to the file in the telescope sqlite file as I showed in my config...

@Tej12345
Copy link

Tej12345 commented Jul 5, 2023

Hi @fireboy1919, I got the same error, but do not know the path of the garbage file. Could you tell me its path?

He means the one that u set in the path:

require("telescope").setup {
  defaults = {
    wrap_results = true,
    history = {
      path = '~/.local/share/nvim/databases/telescope_history.sqlite3',
      limit = 100
    }
  }
}

So just delete telescope_history.sqlite3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants