@@ -19,11 +19,14 @@ local ngx_shared = ngx.shared
19
19
local getmetatable = getmetatable
20
20
21
21
22
+ local MAX_ERR_MSG_LEN = 128
23
+
24
+
22
25
ffi .cdef [[
23
26
int ngx_http_lua_ffi_shdict_get (void * zone , const unsigned char * key ,
24
27
size_t key_len , int * value_type , unsigned char ** str_value_buf ,
25
28
size_t * str_value_len , double * num_value , int * user_flags ,
26
- int get_stale , int * is_stale );
29
+ int get_stale , int * is_stale , char ** errmsg );
27
30
28
31
int ngx_http_lua_ffi_shdict_incr (void * zone , const unsigned char * key ,
29
32
size_t key_len , double * value , char ** err , int has_init , double init ,
@@ -201,8 +204,12 @@ local function shdict_get(zone, key)
201
204
local rc = C .ngx_http_lua_ffi_shdict_get (zone , key , key_len , value_type ,
202
205
str_value_buf , value_len ,
203
206
num_value , user_flags , 0 ,
204
- is_stale )
207
+ is_stale , errmsg )
205
208
if rc ~= 0 then
209
+ if errmsg [0 ] then
210
+ return nil , ffi_str (errmsg [0 ])
211
+ end
212
+
206
213
return error (" failed to get the key" )
207
214
end
208
215
@@ -272,8 +279,12 @@ local function shdict_get_stale(zone, key)
272
279
local rc = C .ngx_http_lua_ffi_shdict_get (zone , key , key_len , value_type ,
273
280
str_value_buf , value_len ,
274
281
num_value , user_flags , 1 ,
275
- is_stale )
282
+ is_stale , errmsg )
276
283
if rc ~= 0 then
284
+ if errmsg [0 ] then
285
+ return nil , ffi_str (errmsg [0 ])
286
+ end
287
+
277
288
return error (" failed to get the key" )
278
289
end
279
290
0 commit comments