Skip to content

Commit 4af8960

Browse files
committed
show detailed reason of LoadError as a error message
1 parent c18503c commit 4af8960

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

error.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,9 @@ rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...)
25682568
void
25692569
rb_load_fail(VALUE path, const char *err)
25702570
{
2571-
VALUE mesg = rb_str_buf_new_cstr(err);
2571+
VALUE mesg = rb_str_buf_new_cstr("cannot load such file");
2572+
rb_str_cat2(mesg, " -- ");
2573+
rb_str_cat2(mesg, err);
25722574
rb_str_cat2(mesg, " -- ");
25732575
rb_str_append(mesg, path);/* should be ASCII compatible */
25742576
raise_loaderror(path, mesg);

file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5813,6 +5813,9 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
58135813
*filep = copy_path_class(fname, *filep);
58145814
return (int)(i+1);
58155815
}
5816+
else if (errno != ENOENT) {
5817+
return 0;
5818+
}
58165819
rb_str_set_len(fname, fnlen);
58175820
}
58185821
return 0;
@@ -5838,6 +5841,9 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
58385841
*filep = copy_path_class(tmp, *filep);
58395842
return (int)(j+1);
58405843
}
5844+
else if (errno != ENOENT) {
5845+
return 0;
5846+
}
58415847
FL_UNSET(tmp, FL_TAINT);
58425848
}
58435849
rb_str_set_len(fname, fnlen);

load.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ rb_provide(const char *feature)
573573
rb_provide_feature(rb_fstring_cstr(feature));
574574
}
575575

576-
NORETURN(static void load_failed(VALUE));
577576
const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);
578577

579578
static int
@@ -654,7 +653,7 @@ static VALUE
654653
file_to_load(VALUE fname)
655654
{
656655
VALUE tmp = rb_find_file(FilePathValue(fname));
657-
if (!tmp) load_failed(fname);
656+
if (!tmp) rb_load_fail(fname, strerror(errno));
658657
return tmp;
659658
}
660659

@@ -708,7 +707,7 @@ rb_f_load(int argc, VALUE *argv)
708707
path = rb_find_file(fname);
709708
if (!path) {
710709
if (!rb_file_load_ok(RSTRING_PTR(fname)))
711-
load_failed(orig_fname);
710+
rb_load_fail(orig_fname, strerror(errno));
712711
path = fname;
713712
}
714713
rb_load_internal(path, RTEST(wrap));
@@ -935,12 +934,6 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
935934
return type ? 's' : 'r';
936935
}
937936

938-
static void
939-
load_failed(VALUE fname)
940-
{
941-
rb_load_fail(fname, "cannot load such file");
942-
}
943-
944937
static VALUE
945938
load_ext(VALUE path)
946939
{
@@ -1048,7 +1041,7 @@ rb_require_safe(VALUE fname, int safe)
10481041
JUMP_TAG(result);
10491042
}
10501043
if (result < 0) {
1051-
load_failed(fname);
1044+
rb_load_fail(fname, strerror(errno));
10521045
}
10531046

10541047
return result ? Qtrue : Qfalse;

0 commit comments

Comments
 (0)