summaryrefslogtreecommitdiffstats
path: root/acf/model/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acf/model/init.lua')
-rw-r--r--acf/model/init.lua26
1 files changed, 16 insertions, 10 deletions
diff --git a/acf/model/init.lua b/acf/model/init.lua
index f333886..44b1f5e 100644
--- a/acf/model/init.lua
+++ b/acf/model/init.lua
@@ -5,6 +5,10 @@ See LICENSE file for license details
module(..., package.seeall)
+error = require('acf.error')
+local raise = error.raise
+local relabel = error.relabel
+
local fld = require('acf.model.field')
local Field = fld.Field
@@ -34,7 +38,7 @@ local Primitive = class(Field)
function Primitive:validate(txn, path, value)
local t = self.dtype
- if type(value) ~= t then error('Not a '..t..': '..tostring(value)) end
+ if type(value) ~= t then raise(path, 'Not a '..t) end
end
@@ -48,7 +52,7 @@ end
function String:validate(txn, path, value)
super(self, String):validate(txn, path, value)
if self['max-length'] and string.len(value) > self['max-length'] then
- error('Maximum length exceeded: '..value)
+ raise(path, 'Maximum length exceeded')
end
end
@@ -79,7 +83,7 @@ Integer = class(Number)
function Integer:validate(txn, path, value)
super(self, Integer):validate(txn, path, value)
- if math.floor(value) ~= value then error('Not an integer: '..value) end
+ if math.floor(value) ~= value then raise(path, 'Not an integer') end
end
@@ -101,7 +105,7 @@ end
function Range:validate(txn, path, value)
local comps = stringy.split(value, '-')
- if #comps > 2 then error('Invalid range') end
+ if #comps > 2 then raise(path, 'Invalid range') end
for _, v in ipairs(comps) do
to_field(self.type):_validate(txn, path, v)
end
@@ -124,8 +128,9 @@ function Reference:meta(txn, path, addr)
local res = super(self, Reference):meta(txn, path, addr)
res.scope = self:abs_scope(path)
- local base = txn:search(res.scope)
- local objs = base and txn:get(getmetatable(base).addr) or {}
+ local objs = txn:get(
+ getmetatable(relabel('system', txn.search, txn, res.scope)).addr
+ ) or {}
res.choice = map(function(p) return pth.join(res.scope, p) end, objs)
res['ui-choice'] = objs
@@ -153,17 +158,18 @@ function Reference:_validate(txn, path, value)
local scope = self:abs_scope(path)
local prefix = scope..'/'
if not stringy.startswith(value, prefix) then
- error('Reference out of scope ('..scope..')')
+ raise(path, 'Reference out of scope ('..scope..')')
end
value = string.sub(value, string.len(prefix) + 1, -1)
end
-- assume one-level ref for now
- assert(not string.find(value, '/'))
- if not self:follow(txn, path, value) then
- error('Does not exist: '..value)
+ if string.find(value, '/') then
+ raise(path, 'Subtree references not yet supported')
end
+
-- TODO check instance type
+ relabel(path, self.follow, self, txn, path, value)
return value
end