From 05c61ca2ce49d36849dd1bafa304e1a2f5db319c Mon Sep 17 00:00:00 2001 From: snail Date: Mon, 2 Feb 2015 19:35:45 +0800 Subject: [PATCH] needless 'string.format', accurate error info remove needless 'string.format' as param of assert, add detail error info for not exist interface. --- lualib/snax.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lualib/snax.lua b/lualib/snax.lua index 6a01460f..13c79f95 100644 --- a/lualib/snax.lua +++ b/lualib/snax.lua @@ -22,6 +22,7 @@ function snax.interface(name) local si = snax_interface(name, G) local ret = { + name = name, accept = {}, response = {}, system = {}, @@ -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 @@ -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