Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRISM] Fix error handling in pm_parse_prism #9862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7811,7 +7811,13 @@ VALUE
pm_parse_file(pm_parse_result_t *result, VALUE filepath)
{
if (!pm_string_mapped_init(&result->input, RSTRING_PTR(filepath))) {
return rb_exc_new3(rb_eRuntimeError, rb_sprintf("Failed to map file: %s", RSTRING_PTR(filepath)));
#ifdef _WIN32
int e = rb_w32_map_errno(GetLastError());
#else
int e = errno;
#endif

return rb_syserr_new(e, RSTRING_PTR(filepath));
}

VALUE error = pm_parse_input(result, filepath);
Expand Down
16 changes: 16 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,22 @@ def test_encoding
assert_prism_eval(":però")
end

def test_parse_file
assert_nothing_raised do
RubyVM::InstructionSequence.compile_file_prism(__FILE__)
end

error = assert_raise Errno::ENOENT do
RubyVM::InstructionSequence.compile_file_prism("idontexist.rb")
end

assert_equal "No such file or directory - idontexist.rb", error.message

assert_raise TypeError do
RubyVM::InstructionSequence.compile_file_prism(nil)
end
end

private

def compare_eval(source, raw:)
Expand Down