Optimized uvl.errors
This commit is contained in:
parent
9a8cd55c36
commit
c939a799ce
1 changed files with 15 additions and 7 deletions
|
@ -14,11 +14,19 @@ $Id$
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
module( "luci.uvl.errors", package.seeall )
|
local uci = require "luci.model.uci"
|
||||||
|
local uvl = require "luci.uvl"
|
||||||
|
local util = require "luci.util"
|
||||||
|
local string = require "string"
|
||||||
|
|
||||||
require("luci.util")
|
local ipairs, error, type = ipairs, error, type
|
||||||
|
local tonumber, unpack = tonumber, unpack
|
||||||
|
|
||||||
|
|
||||||
|
local luci = luci
|
||||||
|
|
||||||
|
module "luci.uvl.errors"
|
||||||
|
|
||||||
ERRCODES = {
|
ERRCODES = {
|
||||||
{ 'UCILOAD', 'Unable to load config "%p": %1' },
|
{ 'UCILOAD', 'Unable to load config "%p": %1' },
|
||||||
|
|
||||||
|
@ -68,11 +76,11 @@ ERRCODES = {
|
||||||
|
|
||||||
-- build error constants and instance constructors
|
-- build error constants and instance constructors
|
||||||
for i, v in ipairs(ERRCODES) do
|
for i, v in ipairs(ERRCODES) do
|
||||||
luci.uvl.errors[v[1]] = function(...)
|
_M[v[1]] = function(...)
|
||||||
return error(i, ...)
|
return error(i, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
luci.uvl.errors['ERR_'..v[1]] = i
|
_M['ERR_'..v[1]] = i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,14 +93,14 @@ function i18n(key, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
error = luci.util.class()
|
error = util.class()
|
||||||
|
|
||||||
function error.__init__(self, code, pso, args)
|
function error.__init__(self, code, pso, args)
|
||||||
|
|
||||||
self.code = code
|
self.code = code
|
||||||
self.args = ( type(args) == "table" and args or { args } )
|
self.args = ( type(args) == "table" and args or { args } )
|
||||||
|
|
||||||
if luci.util.instanceof( pso, luci.uvl.uvlitem ) then
|
if util.instanceof( pso, uvl.uvlitem ) then
|
||||||
self.stype = pso.sref[2]
|
self.stype = pso.sref[2]
|
||||||
self.package, self.section, self.option, self.value = unpack(pso.cref)
|
self.package, self.section, self.option, self.value = unpack(pso.cref)
|
||||||
self.object = pso
|
self.object = pso
|
||||||
|
@ -101,7 +109,7 @@ function error.__init__(self, code, pso, args)
|
||||||
pso = ( type(pso) == "table" and pso or { pso } )
|
pso = ( type(pso) == "table" and pso or { pso } )
|
||||||
|
|
||||||
if pso[2] then
|
if pso[2] then
|
||||||
local uci = luci.model.uci.cursor()
|
local uci = uci.cursor()
|
||||||
self.stype = uci:get(pso[1], pso[2]) or pso[2]
|
self.stype = uci:get(pso[1], pso[2]) or pso[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue