Skip to content

Commit

Permalink
Standartize "Space doesn't exist" error message
Browse files Browse the repository at this point in the history
Part of #224
  • Loading branch information
DifferentialOrange committed Dec 15, 2021
1 parent 1b75f4d commit 6fcf363
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions crud/borders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local function get_border_on_storage(border_name, space_name, index_id, field_na

local space = box.space[space_name]
if space == nil then
return nil, BorderError:new("Space %q doesn't exist", space_name)
return nil, BorderError:new(utils.space_doesnt_exist_msg(space_name))
end

local index = space.index[index_id]
Expand Down Expand Up @@ -76,7 +76,7 @@ local function call_get_border_on_router(border_name, space_name, index_name, op

local space = utils.get_space(space_name, vshard.router.routeall())
if space == nil then
return nil, BorderError:new("Space %q doesn't exist", space_name), true
return nil, BorderError:new(utils.space_doesnt_exist_msg(space_name)), true
end

local index
Expand Down
6 changes: 5 additions & 1 deletion crud/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end
function utils.get_space_format(space_name, replicasets)
local space = utils.get_space(space_name, replicasets)
if space == nil then
return nil, GetSpaceFormatError:new("Space %q doesn't exist", space_name)
return nil, GetSpaceFormatError:new(utils.space_doesnt_exist_msg(space_name))
end

local space_format = space:format()
Expand Down Expand Up @@ -606,4 +606,8 @@ function utils.merge_options(opts_a, opts_b)
return fun.chain(opts_a or {}, opts_b or {}):tomap()
end

function utils.space_doesnt_exist_msg(space_name)
return ("Space %q doesn't exist"):format(space_name)
end

return utils
4 changes: 2 additions & 2 deletions crud/delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function delete_on_storage(space_name, key, field_names)

local space = box.space[space_name]
if space == nil then
return nil, DeleteError:new("Space %q doesn't exist", space_name)
return nil, DeleteError:new(utils.space_doesnt_exist_msg(space_name))
end

-- add_space_schema_hash is false because
Expand Down Expand Up @@ -49,7 +49,7 @@ local function call_delete_on_router(space_name, key, opts)

local space = utils.get_space(space_name, vshard.router.routeall())
if space == nil then
return nil, DeleteError:new("Space %q doesn't exist", space_name), true
return nil, DeleteError:new(utils.space_doesnt_exist_msg(space_name)), true
end

if box.tuple.is(key) then
Expand Down
4 changes: 2 additions & 2 deletions crud/get.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function get_on_storage(space_name, key, field_names)

local space = box.space[space_name]
if space == nil then
return nil, GetError:new("Space %q doesn't exist", space_name)
return nil, GetError:new(utils.space_doesnt_exist_msg(space_name))
end

-- add_space_schema_hash is false because
Expand Down Expand Up @@ -52,7 +52,7 @@ local function call_get_on_router(space_name, key, opts)

local space = utils.get_space(space_name, vshard.router.routeall())
if space == nil then
return nil, GetError:new("Space %q doesn't exist", space_name), true
return nil, GetError:new(utils.space_doesnt_exist_msg(space_name)), true
end

if box.tuple.is(key) then
Expand Down
4 changes: 2 additions & 2 deletions crud/insert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local function insert_on_storage(space_name, tuple, opts)

local space = box.space[space_name]
if space == nil then
return nil, InsertError:new("Space %q doesn't exist", space_name)
return nil, InsertError:new(utils.space_doesnt_exist_msg_msg(space_name))
end

-- add_space_schema_hash is true only in case of insert_object
Expand Down Expand Up @@ -55,7 +55,7 @@ local function call_insert_on_router(space_name, tuple, opts)

local space = utils.get_space(space_name, vshard.router.routeall())
if space == nil then
return nil, InsertError:new("Space %q doesn't exist", space_name), true
return nil, InsertError:new(utils.space_doesnt_exist_msg(space_name)), true
end

local bucket_id, err = sharding.tuple_set_and_return_bucket_id(tuple, space, opts.bucket_id)
Expand Down
2 changes: 1 addition & 1 deletion crud/len.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function len.call(space_name, opts)

local space = utils.get_space(space_name, vshard.router.routeall())
if space == nil then
return nil, LenError:new("Space %q doesn't exist", space_name)
return nil, LenError:new(utils.space_doesnt_exist_msg(space_name))
end

local results, err = vshard.router.map_callrw(LEN_FUNC_NAME, {space_name}, opts)
Expand Down
4 changes: 2 additions & 2 deletions crud/replace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local function replace_on_storage(space_name, tuple, opts)

local space = box.space[space_name]
if space == nil then
return nil, ReplaceError:new("Space %q doesn't exist", space_name)
return nil, ReplaceError:new(utils.space_doesnt_exist_msg(space_name))
end

-- add_space_schema_hash is true only in case of replace_object
Expand Down Expand Up @@ -59,7 +59,7 @@ local function call_replace_on_router(space_name, tuple, opts)
end

if space == nil then
return nil, ReplaceError:new("Space %q doesn't exist", space_name), true
return nil, ReplaceError:new(utils.space_doesnt_exist_msg(space_name)), true
end

local bucket_id, err = sharding.tuple_set_and_return_bucket_id(tuple, space, opts.bucket_id)
Expand Down
2 changes: 1 addition & 1 deletion crud/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ local function select_on_storage(space_name, index_id, conditions, opts)

local space = box.space[space_name]
if space == nil then
return nil, SelectError:new("Space %q doesn't exist", space_name)
return nil, SelectError:new(utils.space_doesnt_exist_msg(space_name))
end

local index = space.index[index_id]
Expand Down
2 changes: 1 addition & 1 deletion crud/select/compat/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local function build_select_iterator(space_name, user_conditions, opts)

local space = utils.get_space(space_name, replicasets)
if space == nil then
return nil, SelectError:new("Space %q doesn't exist", space_name), true
return nil, SelectError:new(utils.space_doesnt_exist_msg(space_name)), true
end
local space_format = space:format()
local sharding_key_as_index_obj, err = sharding_key_module.fetch_on_router(space_name)
Expand Down
2 changes: 1 addition & 1 deletion crud/select/compat/select_old.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ local function build_select_iterator(space_name, user_conditions, opts)

local space = utils.get_space(space_name, replicasets)
if space == nil then
return nil, SelectError:new("Space %q doesn't exist", space_name), true
return nil, SelectError:new(utils.space_doesnt_exist_msg(space_name)), true
end
local space_format = space:format()
local sharding_key_as_index_obj, err = sharding_key_module.fetch_on_router(space_name)
Expand Down
3 changes: 2 additions & 1 deletion crud/truncate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local vshard = require('vshard')

local dev_checks = require('crud.common.dev_checks')
local call = require('crud.common.call')
local utils = require('crud.common.utils')

local TruncateError = errors.new_class('TruncateError', {capture_stack = false})

Expand All @@ -16,7 +17,7 @@ local function truncate_on_storage(space_name)

local space = box.space[space_name]
if space == nil then
return nil, TruncateError:new("Space %q doesn't exist", space_name)
return nil, TruncateError:new(utils.space_doesnt_exist_msg(space_name))
end

return space:truncate()
Expand Down
4 changes: 2 additions & 2 deletions crud/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function update_on_storage(space_name, key, operations, field_names)

local space = box.space[space_name]
if space == nil then
return nil, UpdateError:new("Space %q doesn't exist", space_name)
return nil, UpdateError:new(utils.space_doesnt_exist_msg(space_name))
end

-- add_space_schema_hash is false because
Expand Down Expand Up @@ -75,7 +75,7 @@ local function call_update_on_router(space_name, key, user_operations, opts)
end

if space == nil then
return nil, UpdateError:new("Space %q doesn't exist", space_name), true
return nil, UpdateError:new(utils.space_doesnt_exist_msg(space_name)), true
end

local space_format = space:format()
Expand Down
4 changes: 2 additions & 2 deletions crud/upsert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local function upsert_on_storage(space_name, tuple, operations, opts)

local space = box.space[space_name]
if space == nil then
return nil, UpsertError:new("Space %q doesn't exist", space_name)
return nil, UpsertError:new(utils.space_doesnt_exist_msg(space_name))
end

-- add_space_schema_hash is true only in case of upsert_object
Expand Down Expand Up @@ -57,7 +57,7 @@ local function call_upsert_on_router(space_name, tuple, user_operations, opts)
end

if space == nil then
return nil, UpsertError:new("Space %q doesn't exist", space_name), true
return nil, UpsertError:new(utils.space_doesnt_exist_msg(space_name)), true
end

local space_format = space:format()
Expand Down

0 comments on commit 6fcf363

Please sign in to comment.