Kouhei Sutou
null+****@clear*****
Tue Oct 8 23:49:56 JST 2013
Kouhei Sutou 2013-10-08 23:49:56 +0900 (Tue, 08 Oct 2013) New Revision: fd8fc554a7c3390279125a52ca5f34b0e87242fe https://github.com/groonga/groonga/commit/fd8fc554a7c3390279125a52ca5f34b0e87242fe Message: mruby: treat "no such file" case as error Modified files: lib/mrb.c test/command/suite/ruby/load/nonexistent.expected Modified: lib/mrb.c (+9 -3) =================================================================== --- lib/mrb.c 2013-10-08 23:42:21 +0900 (0933557) +++ lib/mrb.c 2013-10-08 23:49:56 +0900 (b9baa5f) @@ -94,6 +94,13 @@ grn_mrb_open_script(grn_ctx *ctx, const char *path) strcat(expanded_path, path); script_file = fopen(expanded_path, "r"); + if (!script_file) { + char message[BUFFER_SIZE]; + snprintf(message, BUFFER_SIZE - 1, + "fopen: failed to open mruby script file: <%s>", path); + SERR(message); + return NULL; + } return script_file; } @@ -114,9 +121,8 @@ grn_mrb_load(grn_ctx *ctx, const char *path) file = grn_mrb_open_script(ctx, path); if (!file) { mrb_value exception; - char message[BUFFER_SIZE]; - snprintf(message, BUFFER_SIZE - 1, "can't find script: <%s>", path); - exception = mrb_exc_new(mrb, E_ARGUMENT_ERROR, message, strlen(message)); + exception = mrb_exc_new(mrb, E_ARGUMENT_ERROR, + ctx->errbuf, strlen(ctx->errbuf)); mrb->exc = mrb_obj_ptr(exception); return mrb_nil_value(); } Modified: test/command/suite/ruby/load/nonexistent.expected (+16 -1) =================================================================== --- test/command/suite/ruby/load/nonexistent.expected 2013-10-08 23:42:21 +0900 (a9a4708) +++ test/command/suite/ruby/load/nonexistent.expected 2013-10-08 23:49:56 +0900 (d7b9307) @@ -1,4 +1,19 @@ register ruby/load [[0,0.0,0.0],true] ruby_load "nonexistent.rb" -[[0,0.0,0.0],{"exception":{"message":"can't find script: <nonexistent.rb>"}}] +[ + [ + [ + -3, + 0.0, + 0.0 + ], + "syscall error 'fopen: failed to open mruby script file: <nonexistent.rb>' (No such file or directory)" + ], + { + "exception": { + "message": "syscall error 'fopen: failed to open mruby script file: <nonexistent.rb>' (No such file or directory)" + } + } +] +#|e| syscall error 'fopen: failed to open mruby script file: <nonexistent.rb>' (No such file or directory) -------------- next part -------------- HTML����������������������������...Download