Skip to content

Commit 05c61ca

Browse files
committed
needless 'string.format', accurate error info
remove needless 'string.format' as param of assert, add detail error info for not exist interface.
1 parent 7399497 commit 05c61ca

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lualib/snax.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function snax.interface(name)
2222
local si = snax_interface(name, G)
2323

2424
local ret = {
25+
name = name,
2526
accept = {},
2627
response = {},
2728
system = {},
@@ -44,7 +45,10 @@ local skynet_call = skynet.call
4445
local function gen_post(type, handle)
4546
return setmetatable({} , {
4647
__index = function( t, k )
47-
local id = assert(type.accept[k] , string.format("post %s no exist", k))
48+
local id = type.accept[k]
49+
if not id then
50+
error(string.format("post %s:%s no exist", type.name, k))
51+
end
4852
return function(...)
4953
skynet_send(handle, "snax", id, ...)
5054
end
@@ -54,7 +58,10 @@ end
5458
local function gen_req(type, handle)
5559
return setmetatable({} , {
5660
__index = function( t, k )
57-
local id = assert(type.response[k] , string.format("request %s no exist", k))
61+
local id = type.response[k]
62+
if not id then
63+
error(string.format("request %s:%s no exist", type.name, k))
64+
end
5865
return function(...)
5966
return skynet_call(handle, "snax", id, ...)
6067
end

0 commit comments

Comments
 (0)