return err for buffer functions

This commit is contained in:
Lion
2022-07-06 13:14:39 +08:00
parent f87bee3f20
commit 0b8146fa5f
3 changed files with 37 additions and 21 deletions

View File

@@ -65,11 +65,15 @@ end
-- create the searcher based on the cache-policy
local searcher, v_index, content
if cachePolicy == "file" then
searcher = xdb.new_with_file_only(dbFile)
searcher, err = xdb.new_with_file_only(dbFile)
if err ~= nil then
print(string.format("failed to create searcher: %s", err))
return
end
elseif cachePolicy == "vectorIndex" then
v_index = xdb.load_vector_index(dbFile)
if v_index == nil then
print(string.format("failed to load vector index from '%s'", dbFile))
v_index, err = xdb.load_vector_index(dbFile)
if err ~= nil then
print(string.format("failed to load vector index: %s", err))
return
end
@@ -79,8 +83,8 @@ elseif cachePolicy == "vectorIndex" then
return
end
elseif cachePolicy == "content" then
content = xdb.load_content(dbFile)
if content == nil then
content, err = xdb.load_content(dbFile)
if err ~= nil then
print(string.format("failed to load xdb content from '%s'", dbFile))
return
end
@@ -174,4 +178,4 @@ if count > 0 then
avg_costs = c_time / count
end
print(string.format("Bench finished, {cachePolicy: %s, total: %d, took: %.3f s, cost: %.3f μs/op}",
cachePolicy, count, (xdb.now() - s_time)/1e6, c_time / count))
cachePolicy, count, (xdb.now() - s_time)/1e6, c_time / count))