Software /
code /
prosody
Comparison
core/modulemanager.lua @ 13829:dde0ce03049b 13.0
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 09 Apr 2025 10:53:37 +0100 |
parent | 13689:6049c1602c79 |
comparison
equal
deleted
inserted
replaced
13828:a071b20ccc0f | 13829:dde0ce03049b |
---|---|
52 local _G = _G; | 52 local _G = _G; |
53 | 53 |
54 local _ENV = nil; | 54 local _ENV = nil; |
55 -- luacheck: std none | 55 -- luacheck: std none |
56 | 56 |
57 local function plugin_load_filter_cb(path, content) | |
58 local metadata = {}; | |
59 for line in content:gmatch("([^\r\n]+)\r?\n") do | |
60 local key, value = line:match("^%-%-%% *([%w_]+): *(.+)$"); | |
61 if key then | |
62 value = value:gsub("%s+$", ""); | |
63 metadata[key] = value; | |
64 end | |
65 end | |
66 | |
67 if metadata.lua then | |
68 local supported = false; | |
69 for supported_lua_version in metadata.lua:gmatch("[^, ]+") do | |
70 if supported_lua_version == lua_version then | |
71 supported = true; | |
72 break; | |
73 end | |
74 end | |
75 if not supported then | |
76 if prosody.process_type ~= "prosodyctl" then | |
77 log("warn", "Not loading module, we have Lua %s but the module requires one of (%s): %s", lua_version, metadata.lua, path); | |
78 end | |
79 return nil, "incompatible with Lua "..lua_version; -- Don't load this module | |
80 end | |
81 end | |
82 | |
83 if metadata.conflicts then | |
84 local conflicts_features = set.new(array.collect(metadata.conflicts:gmatch("[^, ]+"))); | |
85 local conflicted_features = set.intersection(conflicts_features, core_features); | |
86 if not conflicted_features:empty() then | |
87 if prosody.process_type ~= "prosodyctl" then | |
88 log("warn", "Not loading module, due to conflict with built-in features '%s': %s", conflicted_features, path); | |
89 end | |
90 return nil, "conflict with built-in feature"; -- Don't load this module | |
91 end | |
92 end | |
93 if metadata.requires then | |
94 local required_features = set.new(array.collect(metadata.requires:gmatch("[^, ]+"))); | |
95 local missing_features = required_features - core_features; | |
96 if not missing_features:empty() then | |
97 if prosody.process_type ~= "prosodyctl" then | |
98 log("warn", "Not loading module, due to missing features '%s': %s", missing_features, path); | |
99 end | |
100 return nil, "Prosody version missing required feature"; -- Don't load this module | |
101 end | |
102 end | |
103 | |
104 return path, content, metadata; | |
105 end; | |
106 | |
57 local loader = pluginloader.init({ | 107 local loader = pluginloader.init({ |
58 load_filter_cb = function (path, content) | 108 load_filter_cb = plugin_load_filter_cb; |
59 local metadata = {}; | |
60 for line in content:gmatch("([^\r\n]+)\r?\n") do | |
61 local key, value = line:match("^%-%-%% *([%w_]+): *(.+)$"); | |
62 if key then | |
63 value = value:gsub("%s+$", ""); | |
64 metadata[key] = value; | |
65 end | |
66 end | |
67 | |
68 if metadata.lua then | |
69 local supported = false; | |
70 for supported_lua_version in metadata.lua:gmatch("[^, ]+") do | |
71 if supported_lua_version == lua_version then | |
72 supported = true; | |
73 break; | |
74 end | |
75 end | |
76 if not supported then | |
77 log("warn", "Not loading module, we have Lua %s but the module requires one of (%s): %s", lua_version, metadata.lua, path); | |
78 return; -- Don't load this module | |
79 end | |
80 end | |
81 | |
82 if metadata.conflicts then | |
83 local conflicts_features = set.new(array.collect(metadata.conflicts:gmatch("[^, ]+"))); | |
84 local conflicted_features = set.intersection(conflicts_features, core_features); | |
85 if not conflicted_features:empty() then | |
86 log("warn", "Not loading module, due to conflicting features '%s': %s", conflicted_features, path); | |
87 return; -- Don't load this module | |
88 end | |
89 end | |
90 if metadata.requires then | |
91 local required_features = set.new(array.collect(metadata.requires:gmatch("[^, ]+"))); | |
92 local missing_features = required_features - core_features; | |
93 if not missing_features:empty() then | |
94 log("warn", "Not loading module, due to missing features '%s': %s", missing_features, path); | |
95 return; -- Don't load this module | |
96 end | |
97 end | |
98 | |
99 return path, content, metadata; | |
100 end; | |
101 }); | 109 }); |
102 | 110 |
103 local load_modules_for_host, load, unload, reload, get_module, get_items; | 111 local load_modules_for_host, load, unload, reload, get_module, get_items; |
104 local get_modules, is_loaded, module_has_method, call_module_method; | 112 local get_modules, is_loaded, module_has_method, call_module_method; |
105 | 113 |