Skip to content

Commit 96a30da

Browse files
author
jghauser
committed
fix: proper error handling
1 parent 7f4be79 commit 96a30da

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

lua/papis/completion/init.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77

88
local log = require("papis.log")
99

10-
local has_cmp, cmp = pcall(require, "cmp")
11-
if not has_cmp then
12-
log.error("The plugin nvim-cmp wasn't found but the respective papis.nvim module is configured to be loaded.")
13-
return nil
14-
end
15-
1610
local M = {}
1711

1812
---Sets up the papis.nvim cmp completion source
1913
function M.setup()
2014
log.debug("Cmp: setting up module")
15+
local has_cmp, cmp = pcall(require, "cmp")
16+
if not has_cmp then
17+
error("The plugin nvim-cmp wasn't found but the respective papis.nvim module is configured to be loaded.")
18+
end
19+
2120
require("papis.completion.data").init()
2221
cmp.register_source("papis", require("papis.completion.source").new())
2322
end

lua/papis/init.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ function M.start()
6363
-- set up db
6464
local db = require("papis.sqlite-wrapper")
6565
if not db then
66-
log.error("Requiring `sqlite-wrapper.lua` failed. Aborting...")
67-
return nil
66+
error("Requiring `sqlite-wrapper.lua` failed. Aborting...")
6867
end
6968
db:init()
7069

@@ -76,8 +75,7 @@ function M.start()
7675
-- require what's necessary within `M.start()` instead of globally to allow lazy-loading
7776
local data = require("papis.data")
7877
if not data then
79-
log.error("Requiring `data.lua` failed. Aborting...")
80-
return nil
78+
error("Requiring `data.lua` failed. Aborting...")
8179
end
8280

8381
-- setup commands

lua/papis/search/init.lua

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
--
66

77
local log = require("papis.log")
8-
local has_telescope, telescope = pcall(require, "telescope")
9-
if not has_telescope then
10-
log.error("The plugin telescope.nvim wasn't found but the search module is enabled and requires it.")
11-
return nil
12-
end
13-
local entry_display = require("telescope.pickers.entry_display")
148
local config = require("papis.config")
159
local commands = require("papis.commands")
1610
local keymaps = require("papis.keymaps")
@@ -20,8 +14,6 @@ if not db then
2014
end
2115

2216
local papis_entry_display = {}
23-
setmetatable(papis_entry_display, { __index = entry_display })
24-
papis_entry_display.truncate = function(a) return a end -- HACK: there must better way to turn this off
2517

2618
local telescope_precalc = {}
2719
local precalc_last_updated = 0
@@ -106,6 +98,15 @@ end
10698
---Sets up the papis.nvim telescope extension
10799
function M.setup()
108100
log.debug("Search: setting up module")
101+
local has_telescope, telescope = pcall(require, "telescope")
102+
if not has_telescope then
103+
error("The plugin telescope.nvim wasn't found but the search module is enabled and requires it.")
104+
end
105+
106+
local entry_display = require("telescope.pickers.entry_display")
107+
setmetatable(papis_entry_display, { __index = entry_display })
108+
papis_entry_display.truncate = function(a) return a end -- HACK: there must better way to turn this off
109+
109110
require("papis.search.data").init()
110111
telescope.setup({
111112
extensions = {

lua/papis/sqlite-wrapper.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ local log = require("papis.log")
99

1010
local has_sqlite, sqlite = pcall(require, "sqlite")
1111
if not has_sqlite then
12-
log.error("The dependency 'sqlite.nvim' is missing. Ensure that it is installed to run papis.nvim")
13-
return nil
12+
error("The dependency 'sqlite.nvim' is missing. Ensure that it is installed to run papis.nvim")
1413
end
1514
local sqlite_utils = require "sqlite.utils"
1615

lua/papis/utils.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ end
127127
function M:do_open_text_file(papis_id, type)
128128
local db = require("papis.sqlite-wrapper")
129129
if not db then
130-
log.error("Sqlite-wrapper has not been initialised properly. Aborting...")
131-
return nil
130+
error("Sqlite-wrapper has not been initialised properly. Aborting...")
132131
end
133132
log.debug("Opening a text file")
134133
local entry = db.data:get({ papis_id = papis_id }, { "notes", "id" })[1]

0 commit comments

Comments
 (0)