Skip to content

Commit

Permalink
show detailed reason of LoadError as a error message
Browse files Browse the repository at this point in the history
  • Loading branch information
sonots committed Sep 21, 2017
1 parent c18503c commit 4af8960
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion error.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,9 @@ rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...)
void
rb_load_fail(VALUE path, const char *err)
{
VALUE mesg = rb_str_buf_new_cstr(err);
VALUE mesg = rb_str_buf_new_cstr("cannot load such file");
rb_str_cat2(mesg, " -- ");
rb_str_cat2(mesg, err);
rb_str_cat2(mesg, " -- ");
rb_str_append(mesg, path); /* should be ASCII compatible */
raise_loaderror(path, mesg);
Expand Down
6 changes: 6 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5813,6 +5813,9 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
*filep = copy_path_class(fname, *filep);
return (int)(i+1);
}
else if (errno != ENOENT) {
return 0;
}
rb_str_set_len(fname, fnlen);
}
return 0;
Expand All @@ -5838,6 +5841,9 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
*filep = copy_path_class(tmp, *filep);
return (int)(j+1);
}
else if (errno != ENOENT) {
return 0;
}
FL_UNSET(tmp, FL_TAINT);
}
rb_str_set_len(fname, fnlen);
Expand Down
13 changes: 3 additions & 10 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ rb_provide(const char *feature)
rb_provide_feature(rb_fstring_cstr(feature));
}

NORETURN(static void load_failed(VALUE));
const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);

static int
Expand Down Expand Up @@ -654,7 +653,7 @@ static VALUE
file_to_load(VALUE fname)
{
VALUE tmp = rb_find_file(FilePathValue(fname));
if (!tmp) load_failed(fname);
if (!tmp) rb_load_fail(fname, strerror(errno));
return tmp;
}

Expand Down Expand Up @@ -708,7 +707,7 @@ rb_f_load(int argc, VALUE *argv)
path = rb_find_file(fname);
if (!path) {
if (!rb_file_load_ok(RSTRING_PTR(fname)))
load_failed(orig_fname);
rb_load_fail(orig_fname, strerror(errno));
path = fname;
}
rb_load_internal(path, RTEST(wrap));
Expand Down Expand Up @@ -935,12 +934,6 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
return type ? 's' : 'r';
}

static void
load_failed(VALUE fname)
{
rb_load_fail(fname, "cannot load such file");
}

static VALUE
load_ext(VALUE path)
{
Expand Down Expand Up @@ -1048,7 +1041,7 @@ rb_require_safe(VALUE fname, int safe)
JUMP_TAG(result);
}
if (result < 0) {
load_failed(fname);
rb_load_fail(fname, strerror(errno));
}

return result ? Qtrue : Qfalse;
Expand Down

0 comments on commit 4af8960

Please sign in to comment.