diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-06 23:38:33 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-06 23:38:33 +0000 |
commit | d576a25c26ea6765254e7ec247f951d6bb944703 (patch) | |
tree | 6d2dfbf2f25905f8927f04c9c21d93be796d2b08 /load.c | |
parent | c95cfa0a16305ffb2d701cb2f54bac8b501d86d5 (diff) | |
download | ruby-d576a25c26ea6765254e7ec247f951d6bb944703.tar.gz |
* error.c (rb_loaderror_with_path): Adding the missing file as an
instance variable to the LoadError exception.
* load.c: call rb_loaderror_with_path so that the missing path is
added to the exception.
* ruby.c: call rb_loaderror rather than raising our own LoadError
exception.
* include/ruby/intern.h: add declaration for rb_loaderror_with_path.
* test/ruby/test_require.rb: add supporting test for LoadError#path
method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'load.c')
-rw-r--r-- | load.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -495,7 +495,7 @@ rb_f_require_relative(VALUE obj, VALUE fname) { VALUE base = rb_current_realfilepath(); if (NIL_P(base)) { - rb_raise(rb_eLoadError, "cannot infer basepath"); + rb_loaderror("cannot infer basepath"); } base = rb_file_dirname(base); return rb_require_safe(rb_file_absolute_path(fname, base), rb_safe_level()); @@ -588,12 +588,13 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level) return type ? 's' : 'r'; } +void rb_loaderror_with_path(VALUE path, const char *fmt, ...); + static void load_failed(VALUE fname) { - VALUE mesg = rb_str_buf_new_cstr("cannot load such file -- "); - rb_str_append(mesg, fname); /* should be ASCII compatible */ - rb_exc_raise(rb_exc_new3(rb_eLoadError, mesg)); + rb_loaderror_with_path(fname, "cannot load such file -- %s", RSTRING_PTR(fname)); + RB_GC_GUARD(fname); } static VALUE |