Skip to content

Commit 8833762

Browse files
committed
use: Improve module import error message
It could be that the module has syntax errors, or that it failed to define or import all its necessary functions and variables, or that it deliberately raised an error based on an error condition. It's better to state plainly that the import failed, and permit the user to ascertain the cause from the module's output, rather than making it sound like the module script is broken.
1 parent 4bb94e2 commit 8833762

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/internal/use

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ for __go_module_name in "$@"; do
9090
__go_module_file="$_GO_SCRIPTS_DIR/lib/$__go_module_name"
9191

9292
if [[ ! -f "$__go_module_file" ]]; then
93-
@go.printf "ERROR: Unknown module: $__go_module_name" >&2
93+
@go.printf "ERROR: Unknown module: $__go_module_name\n" >&2
9494
exit 1
9595
fi
9696
fi
9797
fi
9898

9999
if ! . "$__go_module_file"; then
100-
@go.printf "ERROR: Module contains errors: $__go_module_file" >&2
100+
@go.printf "ERROR: Module import failed for: $__go_module_file\n" >&2
101101
exit 1
102102
fi
103103
done

tests/modules/use.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ teardown() {
7878

7979
local expected=("${IMPORTS[0]##*/} loaded"
8080
"${TEST_MODULES[1]}: line 2: This: command not found"
81-
"ERROR: Module contains errors: ${TEST_MODULES[1]}")
81+
"ERROR: Module import failed for: ${TEST_MODULES[1]}")
8282
local IFS=$'\n'
8383
assert_failure "${expected[*]}"
8484
}

0 commit comments

Comments
 (0)