99#include "utils.h"
1010
1111static VALUE cGraph ;
12- static VALUE eIndexingError ;
1312
1413// Free function for the custom Graph allocator. We always have to call into Rust to free data allocated by it
1514static void graph_free (void * ptr ) {
@@ -27,35 +26,39 @@ static VALUE rdxr_graph_alloc(VALUE klass) {
2726 return TypedData_Wrap_Struct (klass , & graph_type , graph );
2827}
2928
30- // Graph#index_all: (Array[String] file_paths) -> nil
31- // Raises IndexingError if anything failed during indexing
29+ // Graph#index_all: (Array[String] file_paths) -> Array[String]
30+ // Returns an array of IO error messages encountered during indexing
3231static VALUE rdxr_graph_index_all (VALUE self , VALUE file_paths ) {
3332 rdxi_check_array_of_strings (file_paths );
3433
3534 // Convert the given file paths into a char** array, so that we can pass to Rust
3635 size_t length = RARRAY_LEN (file_paths );
3736 char * * converted_file_paths = rdxi_str_array_to_char (file_paths , length );
3837
39- // Get the underying graph pointer and then invoke the Rust index all implementation
38+ // Get the underlying graph pointer and then invoke the Rust index all implementation
4039 void * graph ;
4140 TypedData_Get_Struct (self , void * , & graph_type , graph );
42- const char * error_messages = rdx_index_all (graph , (const char * * )converted_file_paths , length );
41+
42+ size_t error_count = 0 ;
43+ const char * const * errors = rdx_index_all (graph , (const char * * )converted_file_paths , length , & error_count );
4344
4445 // Free the converted file paths and allow the GC to collect them
4546 for (size_t i = 0 ; i < length ; i ++ ) {
4647 free (converted_file_paths [i ]);
4748 }
4849 free (converted_file_paths );
4950
50- // If indexing errors were returned, turn them into a Ruby string, call Rust to free the CString it allocated and
51- // return the Ruby string
52- if (error_messages != NULL ) {
53- VALUE error_string = rb_utf8_str_new_cstr (error_messages );
54- free_c_string (error_messages );
55- rb_raise (eIndexingError , "%s" , StringValueCStr (error_string ));
51+ if (errors == NULL ) {
52+ return rb_ary_new ();
5653 }
5754
58- return Qnil ;
55+ VALUE array = rb_ary_new_capa ((long )error_count );
56+ for (size_t i = 0 ; i < error_count ; i ++ ) {
57+ rb_ary_push (array , rb_utf8_str_new_cstr (errors [i ]));
58+ }
59+
60+ free_c_string_array (errors , error_count );
61+ return array ;
5962}
6063
6164// Size function for the declarations enumerator
@@ -443,9 +446,6 @@ static VALUE rdxr_graph_diagnostics(VALUE self) {
443446}
444447
445448void rdxi_initialize_graph (VALUE mRubydex ) {
446- VALUE eRubydexError = rb_const_get (mRubydex , rb_intern ("Error" ));
447- eIndexingError = rb_define_class_under (mRubydex , "IndexingError" , eRubydexError );
448-
449449 cGraph = rb_define_class_under (mRubydex , "Graph" , rb_cObject );
450450 rb_define_alloc_func (cGraph , rdxr_graph_alloc );
451451 rb_define_method (cGraph , "index_all" , rdxr_graph_index_all , 1 );
0 commit comments