From: Andrew Lewis Date: Tue, 22 Nov 2016 08:36:26 +0000 (+0200) Subject: [Minor] Clean up error handling in fuzzyconvert tool X-Git-Tag: 1.4.1~114^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b6955aff2fbff512108a8c76a0625bea4f7409a;p=rspamd.git [Minor] Clean up error handling in fuzzyconvert tool --- diff --git a/src/rspamadm/fuzzy_convert.lua b/src/rspamadm/fuzzy_convert.lua index a7ee666b9..fb957907a 100644 --- a/src/rspamadm/fuzzy_convert.lua +++ b/src/rspamadm/fuzzy_convert.lua @@ -9,30 +9,26 @@ local function connect_redis(server, password, db) }) if not conn then - print('Cannot connect to ' .. server .. ' error: ' .. err) - return nil, err + return nil, 'Cannot connect: ' .. err end if password then ret = conn:add_cmd('AUTH', {password}) if not ret then - print('Cannot queue command. Error: ' .. err) - return nil, err + return nil, 'Cannot queue command' end end if db then ret = conn:add_cmd('SELECT', {db}) if not ret then - print('Cannot queue command. Error: ' .. err) - return nil, err + return nil, 'Cannot queue command' end end if password or db then ret, err = conn:exec() if not ret then - print('Cannot send commands to ' .. server .. ' error: ' .. err) - return nil, err + return nil, 'Cannot execute queued commands: ' .. err end end @@ -47,21 +43,21 @@ local function send_digests(digests, redis_host, redis_password, redis_db) end local ret for _, v in ipairs(digests) do - ret, err = conn:add_cmd('HMSET', { + ret = conn:add_cmd('HMSET', { 'fuzzy' .. v[1], 'F', v[2], 'V', v[3], }) if not ret then - print('Cannot batch HMSET command: ' .. err) + print('Cannot batch command') return false end - ret, err = conn:add_cmd('EXPIRE', { + ret = conn:add_cmd('EXPIRE', { 'fuzzy' .. v[1], tostring(v[4]), }) if not ret then - print('Cannot batch EXPIRE command: ' .. err) + print('Cannot batch command') return false end end @@ -81,7 +77,7 @@ local function send_shingles(shingles, redis_host, redis_password, redis_db) end local ret for _, v in ipairs(shingles) do - ret, err = conn:add_cmd('SET', { + ret = conn:add_cmd('SET', { 'fuzzy_' .. v[2] .. '_' .. v[1], v[4], }) @@ -89,12 +85,12 @@ local function send_shingles(shingles, redis_host, redis_password, redis_db) print('Cannot batch SET command: ' .. err) return false end - ret, err = conn:add_cmd('EXPIRE', { + ret = conn:add_cmd('EXPIRE', { 'fuzzy_' .. v[2] .. '_' .. v[1], tostring(v[3]), }) if not ret then - print('Cannot batch EXPIRE command: ' .. err) + print('Cannot batch command') return false end end @@ -113,20 +109,20 @@ local function update_counters(total, redis_host, redis_password, redis_db) return false end local ret - ret, err = conn:add_cmd('SET', { + ret = conn:add_cmd('SET', { 'fuzzylocal', total, }) if not ret then - print('Cannot batch SET command: ' .. err) + print('Cannot batch command') return false end - ret, err = conn:add_cmd('SET', { + ret = conn:add_cmd('SET', { 'fuzzy_count', total, }) if not ret then - print('Cannot batch SET command: ' .. err) + print('Cannot batch command') return false end ret, err = conn:exec()