diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-08-28 00:21:43 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-08-28 00:21:43 +0000 |
commit | c2f79950b2ca88947a29b9c480b41962ed95f6f1 (patch) | |
tree | 842d87886cb9470b8b00d4ece068d4aa7c01d079 /libs/uvl/luasrc | |
parent | a3fcd87a7188f7b2986a8e741c53e8def587ce29 (diff) |
* luci/libs: uvl: add uci error mechanism to uvl error handling
Diffstat (limited to 'libs/uvl/luasrc')
-rw-r--r-- | libs/uvl/luasrc/uvl.lua | 46 | ||||
-rw-r--r-- | libs/uvl/luasrc/uvl/errors.lua | 4 |
2 files changed, 26 insertions, 24 deletions
diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua index 24dc3a25d..c0f09293f 100644 --- a/libs/uvl/luasrc/uvl.lua +++ b/libs/uvl/luasrc/uvl.lua @@ -125,7 +125,7 @@ function UVL.validate_config( self, config, uci ) self.beenthere = { } if not co:config() then - return false, ERR.UCILOAD(co) + return false, co:errors() end local function _uci_foreach( type, func ) @@ -188,7 +188,7 @@ function UVL.validate_section( self, config, section, uci ) self.beenthere = { } if not co:config() then - return false, ERR.UCILOAD(co) + return false, co:errors() end if so:config() then @@ -217,8 +217,8 @@ function UVL.validate_option( self, config, section, option, uci ) local so = co:section( section ) local oo = so:option( option ) - if not co then - return false, oerr:child(ERR.UCILOAD(config)) + if not co:config() then + return false, co:errors() end if so:config() and oo:config() then @@ -347,10 +347,10 @@ function UVL.read_scheme( self, scheme ) local uci = luci.model.uci.cursor() uci:set_confdir( luci.fs.dirname(file) ) - local sd = uci:get_all( luci.fs.basename(file) ) + local sd, err = uci:get_all( luci.fs.basename(file) ) if not sd then - return false, ERR.UCILOAD(so) + return false, ERR.UCILOAD(so, err) end table.insert( schemes, sd ) @@ -677,7 +677,7 @@ function UVL._read_reference( self, values ) if #ref == 2 or #ref == 3 then local co = luci.uvl.config( self, ref[1] ) - if not co:config() then return false, ERR.UCILOAD(ref[1]) end + if not co:config() then return false, co:errors() end for k, v in pairs(co:config()) do if v['.type'] == ref[2] then @@ -825,6 +825,18 @@ function uvlitem.parent(self) end end +function uvlitem._loadconf(self, co, c) + if not co then + local uci, err = luci.model.uci.cursor(), nil + co, err = uci:get_all(c) + + if err then + self:error(ERR.UCILOAD(self, err)) + end + end + return co +end + --- Object representation of a scheme. -- @class scheme @@ -845,14 +857,9 @@ function scheme.__init__(self, scheme, co, c) c, co = co, nil end - if not co then - local uci = luci.model.uci.cursor() - co = uci:get_all(c) - end - self.cref = { c } self.sref = { c } - self.c = co + self.c = self:_loadconf(co, c) self.s = scheme self.t = luci.uvl.TYPE_SCHEME end @@ -917,14 +924,9 @@ function config.__init__(self, scheme, co, c) c, co = co, nil end - if not co then - local uci = luci.model.uci.cursor() - co = uci:get_all(c) - end - self.cref = { c } self.sref = { c } - self.c = co + self.c = self:_loadconf(co, c) self.s = scheme self.t = luci.uvl.TYPE_CONFIG end @@ -972,7 +974,7 @@ section = luci.util.class(uvlitem) function section.__init__(self, scheme, co, c, s) self.cref = { c, s } self.sref = { c, co and co[s] and co[s]['.type'] or s } - self.c = co + self.c = self:_loadconf(co, c) self.s = scheme self.t = luci.uvl.TYPE_SECTION end @@ -1023,7 +1025,7 @@ option = luci.util.class(uvlitem) function option.__init__(self, scheme, co, c, s, o) self.cref = { c, s, o } self.sref = { c, co and co[s] and co[s]['.type'] or s, o } - self.c = co + self.c = self:_loadconf(co, c) self.s = scheme self.t = luci.uvl.TYPE_OPTION end @@ -1072,7 +1074,7 @@ enum = luci.util.class(option) function enum.__init__(self, scheme, co, c, s, o, v) self.cref = { c, s, o, v } self.sref = { c, co and co[s] and co[s]['.type'] or s, o, v } - self.c = co + self.c = self:_loadconf(co, c) self.s = scheme self.t = luci.uvl.TYPE_ENUM end diff --git a/libs/uvl/luasrc/uvl/errors.lua b/libs/uvl/luasrc/uvl/errors.lua index f3ae4b914..d66784859 100644 --- a/libs/uvl/luasrc/uvl/errors.lua +++ b/libs/uvl/luasrc/uvl/errors.lua @@ -18,13 +18,13 @@ module( "luci.uvl.errors", package.seeall ) require("luci.util") ERRCODES = { - { 'UCILOAD', 'Unable to load config "%p" (syntax error or file not found)' }, + { 'UCILOAD', 'Unable to load config "%p": %1' }, { 'SCHEME', 'Error in scheme "%p":\n%c' }, { 'CONFIG', 'Error in config "%p":\n%c' }, { 'SECTION', 'Error in section "%p.%s":\n%c' }, { 'OPTION', 'Error in option "%p.%s.%o":\n%c' }, - { 'REFERENCE', 'Option "%p.%s.%o" has invalid reference specification "%1":\n%c' }, + { 'REFERENCE', 'Option "%p.%s.%o" has invalid reference specification %1:\n%c' }, { 'DEPENDENCY', 'In dependency check for %t "%i":\n%c' }, { 'SME_FIND', 'Can not find scheme "%p" in "%1"' }, |