summaryrefslogtreecommitdiffstats
path: root/acf/model/node.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acf/model/node.lua')
-rw-r--r--acf/model/node.lua13
1 files changed, 9 insertions, 4 deletions
diff --git a/acf/model/node.lua b/acf/model/node.lua
index 083757c..3459fce 100644
--- a/acf/model/node.lua
+++ b/acf/model/node.lua
@@ -5,6 +5,7 @@ See LICENSE file for license details
module(..., package.seeall)
+local raise = require('acf.error').raise
local object = require('acf.object')
local class = object.class
local super = object.super
@@ -51,9 +52,13 @@ end
function TreeNode:search(path)
if #path == 0 then return self end
- local next = path[1]
+ local name = path[1]
+ local next = self[name]
+ if next == nil then
+ raise(getmetatable(self).path, 'Subordinate does not exist: '..name)
+ end
table.remove(path, 1)
- return TreeNode.search(self[next], path)
+ return TreeNode.search(next, path)
end
@@ -65,7 +70,7 @@ function Collection:init(txn, path, addr, field, required)
if required then
txn.validate[path] = function()
if #txn:get(addr) == 0 then
- error('Collection cannot be empty: '..path)
+ raise(path, 'Collection cannot be empty')
end
end
end
@@ -100,7 +105,7 @@ function PrimitiveList:init(txn, path, addr, field, required)
assert(i == tonumber(j))
if mt.field:load(i) == k then return k end
end
- error('Value does not exist: '..k)
+ raise(path, 'Value does not exist: '..k)
end
end