Skip to content

Commit

Permalink
needless 'string.format', accurate error info
Browse files Browse the repository at this point in the history
remove needless 'string.format' as param of assert, add detail error info for not exist interface.
  • Loading branch information
niuys committed Feb 2, 2015
1 parent 7399497 commit 05c61ca
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lualib/snax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function snax.interface(name)
local si = snax_interface(name, G)

local ret = {
name = name,
accept = {},
response = {},
system = {},
Expand All @@ -44,7 +45,10 @@ local skynet_call = skynet.call
local function gen_post(type, handle)
return setmetatable({} , {
__index = function( t, k )
local id = assert(type.accept[k] , string.format("post %s no exist", k))
local id = type.accept[k]
if not id then
error(string.format("post %s:%s no exist", type.name, k))
end
return function(...)
skynet_send(handle, "snax", id, ...)
end
Expand All @@ -54,7 +58,10 @@ end
local function gen_req(type, handle)
return setmetatable({} , {
__index = function( t, k )
local id = assert(type.response[k] , string.format("request %s no exist", k))
local id = type.response[k]
if not id then
error(string.format("request %s:%s no exist", type.name, k))
end
return function(...)
return skynet_call(handle, "snax", id, ...)
end
Expand Down

0 comments on commit 05c61ca

Please sign in to comment.