From 4b7c68ef3142801c2284f2ec1bbe8f403e20c39b Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 27 Nov 2022 23:31:26 +0000 Subject: feedmaker: split file loading off into a function that throws error messages as opposed to the script just crashing --- make-feed.lua | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'make-feed.lua') diff --git a/make-feed.lua b/make-feed.lua index 2b78493..94d9181 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -112,6 +112,17 @@ local function get_file_metadata(file) return sha1, lastmodified end +local function run_file(file, extension) + local runner + if extension == "moon" then + runner = moonscript.loadfile(file) + else + runner = loadfile(file) + end + local worked, out = pcall(runner) + if not worked then err("error when loading "..file..": ".. out) end +end + local function get_macro_metadata(file) local meta = {file = file, name = nil, description = nil, version = nil, author = nil, namespace = nil, depctrl = nil, sha1 = nil, release = nil} -- having all those nils in the table doesn't really do anything in terms of functionality, but it lets me see what i need to put in it @@ -121,11 +132,8 @@ local function get_macro_metadata(file) function include() end -- so it doesnt die with karaskel imports and such - if meta.extension == "moon" then - moonscript.loadfile(file)() - else - loadfile(file)() - end + run_file(file, meta.extension) + -- script_name etc are now in our global scope if config.macros.ignoreCondition() then err(file .. ": ignored by config, skipping") @@ -146,12 +154,8 @@ local function get_module_metadata(file) meta.sha1, meta.release = get_file_metadata(file) meta.basename, meta.extension = split_filename(file) - if meta.extension == "moon" then - moonscript.loadfile(file)() - else - loadfile(file)() - end - -- script_name etc are now in our global scope + run_file(file, meta.extension) + if config.modules.ignoreCondition() then err(file .. ": ignored by config, skipping") return nil -- cgit v1.2.3-70-g09d2