From 097efa9d2d0c881e1ce858d9502890817add49c5 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Fri, 28 Aug 2020 20:34:54 +0200
Subject: [PATCH] scripts: feature_lib.lua: improve error handling for invalid
 feature files

Print a proper error message, rather than just

    openwrt/staging_dir/hostpkg/bin/lua: scripts/feature_lib.lua:48: bad
    argument #1 to 'setfenv' (integer expected, got nil)
---
 scripts/feature_lib.lua | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/feature_lib.lua b/scripts/feature_lib.lua
index 1e910827a..d4cfafe01 100644
--- a/scripts/feature_lib.lua
+++ b/scripts/feature_lib.lua
@@ -43,7 +43,10 @@ function M.get_packages(file, features)
 	end
 
 	-- Evaluate the feature definition file
-	local f = loadfile(file)
+	local f, err = loadfile(file)
+	if not f then
+		error('Failed to parse feature definition: ' .. err)
+	end
 	setfenv(f, funcs)
 	f()
 
-- 
GitLab