From 8d0df029b0da53d049f3b02e5e83b21c6000a583 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 15 Feb 2024 18:45:18 -0300 Subject: fix: avoid nil crash if config_files is not fully filled I couldn't track down which scenarios cause this, but it has happened on Windows: See: https://github.com/lunarmodules/luasystem/pull/17 See: https://github.com/lunarmodules/luasystem/actions/runs/7907096563/job/21583369125?pr=17 --- src/luarocks/cmd/config.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index 6a73c7ff..0227b18d 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -280,7 +280,12 @@ function config_cmd.command(args) return nil, "Current directory is not part of a project. You may want to run `luarocks init`." end - local prefix = dir.dir_name(cfg.config_files[scope].file) + local location = cfg.config_files[scope] + if (not location) or (not location.file) then + return nil, "could not get config file location for " .. tostring(scope) .. " scope" + end + + local prefix = dir.dir_name(location.file) local ok, err = persist.save_default_lua_version(prefix, args.value) if not ok then return nil, "could not set default Lua version: " .. err -- cgit v1.2.3-55-g6feb