diff options
author | eileencodes <[email protected]> | 2024-02-05 14:39:29 -0500 |
---|---|---|
committer | git <[email protected]> | 2024-02-06 20:49:33 +0000 |
commit | 936c0ab5e807e7060e6fc65a3c45015c131ae873 () | |
tree | b35399f77d5c7344b9457a57d5ab7dc882781a05 /lib/prism/ffi.rb | |
parent | c3403322df7d81cd9426310bd7833d005b2a7ac7 (diff) |
[ruby/prism] Implement file parsing error handling
This PR implements proper file parsing error handling. Previously `file_options` would call `pm_string_mapped_init` which would print an error from `perror`. However this wouldn't raise a proper Ruby error so it was just a string output. I've done the following: - Raise an error from `rb_syserr_fail` with the filepath in `file_options`. - No longer return `Qnil` if `file_options` returns false (because now it will raise) - Update `file_options` to return `static void` instead of `static bool`. - Update `file_options` and `profile_file` to check the type so when passing `nil` we see a `TypeError`. - Delete `perror` from `pm_string_mapped_init` - Update `FFI` backend to raise appropriate errors when calling `pm_string_mapped_init`. - Add tests for `dump_file`, `lex_file`, `parse_file`, `parse_file_comments`, `parse_lex_file`, and `parse_file_success?` when a file doesn't exist and for `nil`. - Updates the `bin/parse` script to no longer raise it's own `ArgumentError` now that we raise a proper error. Fixes: ruby/prism#2207 https://.com/ruby/prism/commit/b2f7494ff5
-rw-r--r-- | lib/prism/ffi.rb | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -160,8 +160,13 @@ module Prism pointer = FFI::MemoryPointer.new(SIZEOF) begin - raise unless LibRubyParser.pm_string_mapped_init(pointer, filepath) - yield new(pointer) ensure LibRubyParser.pm_string_free(pointer) pointer.free |