fix: report config parsing errors

Amolith created

Previously, syntax errors in config files were silently ignored, causing
confusing behavior (e.g. "remote 'github' not found").

Both load_global_config and load_project_config now:
- Try loading with and without implicit return
- Report syntax errors with line numbers
- Report execution errors (e.g. undefined variables)
- Report when config doesn't return a table

Assisted-by: Claude Opus 4.5 via Amp

Change summary

src/main.lua | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)

Detailed changes

src/main.lua 🔗

@@ -240,15 +240,24 @@ local function load_global_config()
 	end
 	local content = f:read("*a")
 	f:close()
-	local chunk = load("return " .. content, config_path, "t", {})
+	local chunk, err = load(content, config_path, "t", {})
 	if not chunk then
+		chunk, err = load("return " .. content, config_path, "t", {})
+	end
+	if not chunk then
+		io.stderr:write("warning: config syntax error in " .. config_path .. ": " .. err .. "\n")
 		return {}
 	end
 	local ok, result = pcall(chunk)
-	if ok and type(result) == "table" then
-		return result
+	if not ok then
+		io.stderr:write("warning: config execution error in " .. config_path .. ": " .. result .. "\n")
+		return {}
 	end
-	return {}
+	if type(result) ~= "table" then
+		io.stderr:write("warning: config must return a table in " .. config_path .. "\n")
+		return {}
+	end
+	return result
 end
 
 ---Load project config from <root>/.wt.lua
@@ -263,18 +272,24 @@ local function load_project_config(root)
 	local content = f:read("*a")
 	f:close()
 
-	local chunk = load(content, config_path, "t", {})
+	local chunk, err = load(content, config_path, "t", {})
 	if not chunk then
-		chunk = load("return " .. content, config_path, "t", {})
+		chunk, err = load("return " .. content, config_path, "t", {})
 	end
 	if not chunk then
+		io.stderr:write("warning: config syntax error in " .. config_path .. ": " .. err .. "\n")
 		return {}
 	end
 	local ok, result = pcall(chunk)
-	if ok and type(result) == "table" then
-		return result
+	if not ok then
+		io.stderr:write("warning: config execution error in " .. config_path .. ": " .. result .. "\n")
+		return {}
 	end
-	return {}
+	if type(result) ~= "table" then
+		io.stderr:write("warning: config must return a table in " .. config_path .. "\n")
+		return {}
+	end
+	return result
 end
 
 ---Split path into components