Comparison

util/pubsub.lua @ 10356:0a2d7efca039

util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
author Matthew Wild <mwild1@gmail.com>
date Sun, 27 Oct 2019 14:45:57 +0000
parent 9840:ec353524b739
child 10521:cbb2c3f8bb1d
comparison
equal deleted inserted replaced
10355:cb9755d7a36e 10356:0a2d7efca039
1 local events = require "util.events"; 1 local events = require "util.events";
2 local cache = require "util.cache"; 2 local cache = require "util.cache";
3 local errors = require "util.error";
3 4
4 local service_mt = {}; 5 local service_mt = {};
5 6
6 local default_config = { 7 local default_config = {
7 itemstore = function (config, _) return cache.new(config["max_items"]) end; 8 itemstore = function (config, _) return cache.new(config["max_items"]) end;
508 if not (node_config and required_config) then 509 if not (node_config and required_config) then
509 return false; 510 return false;
510 end 511 end
511 for config_field, value in pairs(required_config) do 512 for config_field, value in pairs(required_config) do
512 if node_config[config_field] ~= value then 513 if node_config[config_field] ~= value then
513 return false; 514 return false, config_field;
514 end 515 end
515 end 516 end
516 return true; 517 return true;
517 end 518 end
518 519
544 return ok, err; 545 return ok, err;
545 end 546 end
546 node_obj = self.nodes[node]; 547 node_obj = self.nodes[node];
547 elseif requested_config and not requested_config._defaults_only then 548 elseif requested_config and not requested_config._defaults_only then
548 -- Check that node has the requested config before we publish 549 -- Check that node has the requested config before we publish
549 if not check_preconditions(node_obj.config, requested_config) then 550 local ok, field = check_preconditions(node_obj.config, requested_config);
550 return false, "precondition-not-met"; 551 if not ok then
552 local err = errors.new({
553 type = "cancel", condition = "conflict", text = "Field does not match: "..field;
554 });
555 err.pubsub_condition = "precondition-not-met";
556 return false, err;
551 end 557 end
552 end 558 end
553 if not self.config.itemcheck(item) then 559 if not self.config.itemcheck(item) then
554 return nil, "invalid-item"; 560 return nil, "invalid-item";
555 end 561 end