Pass on the error message when rel_path is invalid

"Module path must be a string" is not a useful error message when the
reason the module path isn't a string is because the string it was got
replaced with an invalid with an error message for some other reason.

Also fixes a few memory leaks on early exits.
This commit is contained in:
Muh Muhten authored and Nico Williams committed 2019-02-20 19:16:18 -06:00
1 parent 8edf58a95f
commit ff014824bc
1 file changed
+13 -3
+13 -3
View File
@@ -138,10 +138,20 @@ static jv jv_basename(jv name) {
// Asummes validated relative path to module
static jv find_lib(jq_state *jq, jv rel_path, jv search, const char *suffix, jv jq_origin, jv lib_origin) {
if (jv_get_kind(search) != JV_KIND_ARRAY)
return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array"));
if (jv_get_kind(rel_path) != JV_KIND_STRING)
if (!jv_is_valid(rel_path)) {
jv_free(search);
return rel_path;
}
if (jv_get_kind(rel_path) != JV_KIND_STRING) {
jv_free(rel_path);
jv_free(search);
return jv_invalid_with_msg(jv_string_fmt("Module path must be a string"));
}
if (jv_get_kind(search) != JV_KIND_ARRAY) {
jv_free(rel_path);
jv_free(search);
return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array"));
}
struct stat st;
int ret;