Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+module-load-reason.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A build that cannot load the stack module or EESSI-extend shows Lmod's reason, such as an unknown module, under `eb-local: could not load <module>:`. A build dropped everything a load wrote to stderr, so a module missing from `MODULEPATH` and a load hook that failed both read only `could not load`. A load that works stays quiet.
13 changes: 11 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,15 @@ const build_script = "set -eo pipefail\n" ++ (if (build_options.test_ops) test_p
\\declare -A saved
\\for v in "${keep[@]}"; do saved[$v]=${!v}; done
\\restore() { for v in "${keep[@]}"; do export "$v=${saved[$v]}"; done; }
\\# A load that works fills stderr with the modules' own messages; one that
\\# fails leaves Lmod's reason there, so only a failed load shows it.
\\load() {
\\ local err="${saved[TMPDIR]}/module-load.err" line
\\ module load "$1" >/dev/null 2>"$err" && return
\\ echo "eb-local: could not load $1:" >&2
\\ while IFS= read -r line; do echo "${line:+ $line}" >&2; done < "$err"
\\ exit 1
\\}
\\
++ lmod_init ++
\\type module >/dev/null 2>&1 || {
Expand All @@ -1674,7 +1683,7 @@ const build_script = "set -eo pipefail\n" ++ (if (build_options.test_ops) test_p
\\# is on MODULEPATH only once the stack is loaded. The extension reads
\\# WORKING_DIR and EASYBUILD_SOURCEPATH as it loads, so whatever the
\\# stack module set, the paths go back first.
\\module load "$stack" >/dev/null 2>&1 || { echo "eb-local: could not load $stack" >&2; exit 1; }
\\load "$stack"
\\restore
\\# Tasks run with the CPU target eessi-arch-guard selects, which can be
\\# below the one EESSI detects: on a CPU without a flag GCC enables for the
Expand All @@ -1690,7 +1699,7 @@ const build_script = "set -eo pipefail\n" ++ (if (build_options.test_ops) test_p
\\ eval "$delta"
\\ restore
\\fi
\\module load "$extend" >/dev/null 2>&1 || { echo "eb-local: could not load $extend" >&2; exit 1; }
\\load "$extend"
\\restore
\\# EESSI-extend chose the install path as it loaded. eb-local checked the
\\# prefix's versions tree, lists it and cleans its logs of secrets, so an
Expand Down
57 changes: 57 additions & 0 deletions tests/test_module_load_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""A module load in a build, through the command line of the Zig build.

Lmod writes a module's messages to stderr as it loads, and its reason when
a load fails: a build shows only the reason.
"""
import unittest

import binary
from test_storage import StorageFixture

# The module double, chattering on stderr as Lmod does, and failing to load
# CONTROL_LOAD_FAILS with Lmod's message for a module it cannot find.
LOAD = r'''
eval "double_$(declare -f module)"
module() {
if [ "$1" = load ]; then
if [ "$2" = "${CONTROL_LOAD_FAILS:-}" ]; then
echo "Lmod has detected the following error: The following module(s) are unknown: \"$2\"" >&2
echo " module --ignore_cache load \"$2\"" >&2
return 1
fi
echo "Module for $2 loaded successfully" >&2
fi
double_module "$@"
}
export -f module double_module
'''


@unittest.skipUnless(binary.BIN, "showing why a load failed is a feature of the Zig build")
class ModuleLoad(StorageFixture):
def setUp(self):
super().setUp()
with open(self.root / "doubles.sh", "a") as handle:
handle.write(LOAD)

def test_a_load_that_works_stays_quiet(self):
run = self.run_wrapper()
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
self.assertNotIn("loaded successfully", run.stdout + run.stderr)

def test_a_failed_load_says_why(self):
for module in ("EESSI/2026.06", "EESSI-extend/2026.06-easybuild"):
with self.subTest(module=module):
run = self.run_wrapper(CONTROL_LOAD_FAILS=module)
self.assertEqual(run.returncode, 1, run.stdout + run.stderr)
self.assertIn(f"eb-local: could not load {module}:\n"
" Lmod has detected the following error: The following module(s) are unknown: "
f"\"{module}\"\n"
f" module --ignore_cache load \"{module}\"\n", run.stderr)
self.assertNotIn("loaded successfully", run.stderr)
self.assertFalse((self.root / "eb.json").exists())


if __name__ == "__main__":
unittest.main()
Loading