From 37d816eefa656cc9071a363916d71381971e8d38 Mon Sep 17 00:00:00 2001 From: Pascal Elahi Date: Thu, 31 Aug 2023 14:24:11 +0800 Subject: [PATCH] Adding environment checks to pawsey lua for handling errors --- scripts/templates/pawseyenv.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/templates/pawseyenv.lua b/scripts/templates/pawseyenv.lua index 00bd9c7c..adddd311 100644 --- a/scripts/templates/pawseyenv.lua +++ b/scripts/templates/pawseyenv.lua @@ -11,6 +11,30 @@ ]]-- +--[[ +-- There has been issues where the module just fails on first assert and it is unclear +-- from the error message what that issue is. Thus the module also checks for the +-- definition of HOME, USER, PAWSEY_PROJECT etc. +--]] + +local function check_envs() + local envvars = {"HOME", "USER", "PAWSEY_PROJECT"} + for ind,var in ipairs(envvars) do + local env = os.getenv(var) + if env == nil or env == "" then + nid = os.getenv("HOSTNAME") + io.stderr:write("Issue with environment variable used to set module paths:" .. var .. "not set.\n") + io.stderr:write("This could be a result of issues with authentication and LDAP.\n") + io.stderr:write("This occurred on " .. nid .. " node\n") + return + end + end +end + + +-- check that environment is okay +check_envs() + -- Service variables for this module -- --