summaryrefslogtreecommitdiff
path: root/prism/util/pm_string.c
diff options
context:
space:
mode:
authoreileencodes <[email protected]>2024-02-05 14:39:29 -0500
committergit <[email protected]>2024-02-06 20:49:33 +0000
commit936c0ab5e807e7060e6fc65a3c45015c131ae873 (patch)
treeb35399f77d5c7344b9457a57d5ab7dc882781a05 /prism/util/pm_string.c
parentc3403322df7d81cd9426310bd7833d005b2a7ac7 (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://github.com/ruby/prism/commit/b2f7494ff5
Diffstat (limited to 'prism/util/pm_string.c')
-rw-r--r--prism/util/pm_string.c7
1 files changed, 0 insertions, 7 deletions
diff --git a/prism/util/pm_string.c b/prism/util/pm_string.c
index f4d3033a1b..e67fcee0ec 100644
--- a/prism/util/pm_string.c
+++ b/prism/util/pm_string.c
@@ -65,7 +65,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE) {
- perror("CreateFile failed");
return false;
}
@@ -73,7 +72,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
DWORD file_size = GetFileSize(file, NULL);
if (file_size == INVALID_FILE_SIZE) {
CloseHandle(file);
- perror("GetFileSize failed");
return false;
}
@@ -90,7 +88,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
if (mapping == NULL) {
CloseHandle(file);
- perror("CreateFileMapping failed");
return false;
}
@@ -100,7 +97,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
CloseHandle(file);
if (source == NULL) {
- perror("MapViewOfFile failed");
return false;
}
@@ -110,7 +106,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
// Open the file for reading
int fd = open(filepath, O_RDONLY);
if (fd == -1) {
- perror("open");
return false;
}
@@ -118,7 +113,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
struct stat sb;
if (fstat(fd, &sb) == -1) {
close(fd);
- perror("fstat");
return false;
}
@@ -135,7 +129,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (source == MAP_FAILED) {
- perror("Map failed");
return false;
}