]> Kevux Git Server - fll/commitdiff
Update: add missing error handling
authorKevin Day <thekevinday@gmail.com>
Sat, 9 May 2020 00:42:35 +0000 (19:42 -0500)
committerKevin Day <thekevinday@gmail.com>
Sat, 9 May 2020 00:42:35 +0000 (19:42 -0500)
level_3/fss_basic_list_read/c/private-fss_basic_list_read.c
level_3/fss_basic_read/c/private-fss_basic_read.c
level_3/fss_extended_list_read/c/private-fss_extended_list_read.c
level_3/fss_extended_read/c/private-fss_extended_read.c

index 11d63e8c2a23bfcc714bb0fec3e198ead50d6f4d..f41da5dfb867ac24a33be3227b443fd61920360e 100644 (file)
@@ -162,10 +162,39 @@ extern "C" {
           depths->array[i].index_name = data.parameters[fss_basic_list_read_parameter_name].additional.array[position_name];
 
           if (data.parameters[fss_basic_list_read_parameter_trim].result == f_console_result_found) {
-            fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
           }
           else {
-            fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+          }
+
+          if (f_status_is_error(status)) {
+            f_status status_code = f_status_set_fine(status);
+
+            // @todo: move error printing into common function.
+            if (status_code == f_error_allocation || status_code == f_error_reallocation) {
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory.");
+            }
+            else if (status_code == f_string_max_size) {
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: Unable to process '");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s%s", f_console_symbol_long_enable, fss_basic_list_read_long_trim);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' because the maximum buffer size was reached.");
+            }
+            else {
+              f_string function = "fl_string_append";
+
+              if (data.parameters[fss_basic_list_read_parameter_trim].result == f_console_result_found) {
+                function = "fl_string_rip";
+              }
+
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%u", status_code);
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, ") has occurred while calling ");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s()", function);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, ".");
+            }
+
+            return status;
           }
 
           if (depths->array[i].value_name.used == 0) {
index 1eacbd006c14d4a18f4b16314a78f4237d703dbf..445d1ea287c7071b0a26782bd7dfd4e3f41bdb18 100644 (file)
@@ -162,10 +162,39 @@ extern "C" {
           depths->array[i].index_name = data.parameters[fss_basic_read_parameter_name].additional.array[position_name];
 
           if (data.parameters[fss_basic_read_parameter_trim].result == f_console_result_found) {
-            fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
           }
           else {
-            fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+          }
+
+          if (f_status_is_error(status)) {
+            f_status status_code = f_status_set_fine(status);
+
+            // @todo: move error printing into common function.
+            if (status_code == f_error_allocation || status_code == f_error_reallocation) {
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory.");
+            }
+            else if (status_code == f_string_max_size) {
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: Unable to process '");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s%s", f_console_symbol_long_enable, fss_basic_read_long_trim);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' because the maximum buffer size was reached.");
+            }
+            else {
+              f_string function = "fl_string_append";
+
+              if (data.parameters[fss_basic_read_parameter_trim].result == f_console_result_found) {
+                function = "fl_string_rip";
+              }
+
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%u", status_code);
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, ") has occurred while calling ");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s()", function);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, ".");
+            }
+
+            return status;
           }
 
           if (depths->array[i].value_name.used == 0) {
index fb19fcf95ed0d365ddf7c570c6ffdcf844d7d44f..9e106b4bf5281f95e2b67f7000fbb73e3789b30b 100644 (file)
@@ -162,10 +162,39 @@ extern "C" {
           depths->array[i].index_name = data.parameters[fss_extended_list_read_parameter_name].additional.array[position_name];
 
           if (data.parameters[fss_extended_list_read_parameter_trim].result == f_console_result_found) {
-            fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
           }
           else {
-            fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+          }
+
+          if (f_status_is_error(status)) {
+            f_status status_code = f_status_set_fine(status);
+
+            // @todo: move error printing into common function.
+            if (status_code == f_error_allocation || status_code == f_error_reallocation) {
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory.");
+            }
+            else if (status_code == f_string_max_size) {
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: Unable to process '");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s%s", f_console_symbol_long_enable, fss_extended_list_read_long_trim);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' because the maximum buffer size was reached.");
+            }
+            else {
+              f_string function = "fl_string_append";
+
+              if (data.parameters[fss_extended_list_read_parameter_trim].result == f_console_result_found) {
+                function = "fl_string_rip";
+              }
+
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%u", status_code);
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, ") has occurred while calling ");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s()", function);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, ".");
+            }
+
+            return status;
           }
 
           if (depths->array[i].value_name.used == 0) {
index 72fbce576bf758bb0520c48a35032c6d6499747e..b8e233fa89e229aca3d27e8f7a35430643e8f85e 100644 (file)
@@ -162,10 +162,39 @@ extern "C" {
           depths->array[i].index_name = data.parameters[fss_extended_read_parameter_name].additional.array[position_name];
 
           if (data.parameters[fss_extended_read_parameter_trim].result == f_console_result_found) {
-            fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
           }
           else {
-            fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+            status = fl_string_append(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name);
+          }
+
+          if (f_status_is_error(status)) {
+            f_status status_code = f_status_set_fine(status);
+
+            // @todo: move error printing into common function.
+            if (status_code == f_error_allocation || status_code == f_error_reallocation) {
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory.");
+            }
+            else if (status_code == f_string_max_size) {
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: Unable to process '");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s%s", f_console_symbol_long_enable, fss_extended_read_long_trim);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' because the maximum buffer size was reached.");
+            }
+            else {
+              f_string function = "fl_string_append";
+
+              if (data.parameters[fss_extended_read_parameter_trim].result == f_console_result_found) {
+                function = "fl_string_rip";
+              }
+
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%u", status_code);
+              fl_color_print(f_standard_error, data.context.error, data.context.reset, ") has occurred while calling ");
+              fl_color_print(f_standard_error, data.context.notable, data.context.reset, "%s()", function);
+              fl_color_print_line(f_standard_error, data.context.error, data.context.reset, ".");
+            }
+
+            return status;
           }
 
           if (depths->array[i].value_name.used == 0) {