]> Kevux Git Server - fll/commitdiff
Update: Improve error reporting resulting from unsupported file formats.
authorKevin Day <Kevin@kevux.org>
Tue, 3 Sep 2024 03:59:59 +0000 (22:59 -0500)
committerKevin Day <Kevin@kevux.org>
Tue, 3 Sep 2024 03:59:59 +0000 (22:59 -0500)
The file is either an unsupported format or has syntax errors.
Provide a more human-friendly error message rather than the default catch-all error with a status code.

level_1/fl_fss/c/fss/embedded_list.h
level_3/fss_read/c/basic/fss_read.c
level_3/fss_read/c/basic_list/fss_read.c
level_3/fss_read/c/embedded_list/fss_read.c
level_3/fss_read/c/extended/fss_read.c
level_3/fss_read/c/extended_list/fss_read.c
level_3/fss_read/c/main/print/error.c
level_3/fss_read/c/main/print/error.h

index 58dd6a01d235de91b9d4327f6a8cd6ad1cf90fd7..deedba1d3ef3fd2c5c64b88693e13064ee566bc5 100644 (file)
@@ -110,8 +110,12 @@ extern "C" {
  *     F_data_not if buffer is empty (buffer.used is 0).
  *     F_data_not_eos no objects found after reaching the end of the buffer (essentially only comments are found).
  *     F_data_not_stop no data found after reaching stopping point (essentially only comments are found).
+ *     F_end_not_eos If EOS was reached before the Content at depth 0 was fully terminated.
  *     F_end_not_group_eos if EOS was reached before the a group termination was reached.
  *     F_end_not_group_stop if stop point was reached before the a group termination was reached.
+ *     F_end_not_nest_eos If EOS was reached before the Content at depth 1 or greater was fully terminated.
+ *     F_end_not_nest_stop If stop point was reached before the Content at depth 1 or greater was fully terminated.
+ *     F_end_not_stop If stop point was reached before the Content at depth 0 was fully terminated.
  *
  *     F_interrupt (with error bit) if stopping due to an interrupt.
  *     F_parameter (with error bit) if a parameter is invalid.
index 5e5287970baf57404c68735145a850526e5c027d..46ee25162d0c265ba1d4d51f5a08b35cc776c7e2 100644 (file)
@@ -26,15 +26,29 @@ extern "C" {
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
 
-      fll_error_file_print(
-        &main->program.error,
-        F_status_set_fine(main->setting.state.status),
-        macro_fss_read_f(fll_fss_basic_read),
-        fll_error_file_flag_fallback_e,
-        fss_read_file_identify(main->setting.range.start, main->setting.files),
-        f_file_operation_process_s,
-        fll_error_file_type_file_e
-      );
+      // Handle knownable errors with more user-friendly messages.
+      switch (F_status_set_fine(main->setting.state.status)) {
+        case F_end_not_eos:
+        case F_end_not_group_eos:
+        case F_end_not_group_stop:
+        case F_end_not_nest_eos:
+        case F_end_not_nest_stop:
+        case F_end_not_stop:
+          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
+
+          break;
+
+        default:
+          fll_error_file_print(
+            &main->program.error,
+            F_status_set_fine(main->setting.state.status),
+            macro_fss_read_f(fll_fss_basic_read),
+            fll_error_file_flag_fallback_e,
+            fss_read_file_identify(main->setting.range.start, main->setting.files),
+            f_file_operation_process_s,
+            fll_error_file_type_file_e
+          );
+      }
 
       return;
     }
index 8a710d4a433bf86153fba724964566508f7d7d59..4146b914c6029333847496d7dc64040cd651c01a 100644 (file)
@@ -26,15 +26,29 @@ extern "C" {
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
 
-      fll_error_file_print(
-        &main->program.error,
-        F_status_set_fine(main->setting.state.status),
-        macro_fss_read_f(fll_fss_basic_list_read),
-        fll_error_file_flag_fallback_e,
-        fss_read_file_identify(main->setting.range.start, main->setting.files),
-        f_file_operation_process_s,
-        fll_error_file_type_file_e
-      );
+      // Handle knownable errors with more user-friendly messages.
+      switch (F_status_set_fine(main->setting.state.status)) {
+        case F_end_not_eos:
+        case F_end_not_group_eos:
+        case F_end_not_group_stop:
+        case F_end_not_nest_eos:
+        case F_end_not_nest_stop:
+        case F_end_not_stop:
+          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
+
+          break;
+
+        default:
+          fll_error_file_print(
+            &main->program.error,
+            F_status_set_fine(main->setting.state.status),
+            macro_fss_read_f(fll_fss_basic_list_read),
+            fll_error_file_flag_fallback_e,
+            fss_read_file_identify(main->setting.range.start, main->setting.files),
+            f_file_operation_process_s,
+            fll_error_file_type_file_e
+          );
+      }
 
       return;
     }
index 8d532e63b99251dd5f5ed3e9acf938ae3ed2d0df..32da9f2e7148addc3f5f552e5c1d749ff127812c 100644 (file)
@@ -35,15 +35,29 @@ extern "C" {
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
 
-      fll_error_file_print(
-        &main->program.error,
-        F_status_set_fine(main->setting.state.status),
-        macro_fss_read_f(fll_fss_embedded_list_read),
-        fll_error_file_flag_fallback_e,
-        fss_read_file_identify(main->setting.range.start, main->setting.files),
-        f_file_operation_process_s,
-        fll_error_file_type_file_e
-      );
+      // Handle knownable errors with more user-friendly messages.
+      switch (F_status_set_fine(main->setting.state.status)) {
+        case F_end_not_eos:
+        case F_end_not_group_eos:
+        case F_end_not_group_stop:
+        case F_end_not_nest_eos:
+        case F_end_not_nest_stop:
+        case F_end_not_stop:
+          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
+
+          break;
+
+        default:
+          fll_error_file_print(
+            &main->program.error,
+            F_status_set_fine(main->setting.state.status),
+            macro_fss_read_f(fll_fss_embedded_list_read),
+            fll_error_file_flag_fallback_e,
+            fss_read_file_identify(main->setting.range.start, main->setting.files),
+            f_file_operation_process_s,
+            fll_error_file_type_file_e
+          );
+      }
 
       return;
     }
index 89e8136ffbb1da49655f8ae1d610a8afb69968ed..3313c3aa4d09688f557235f466f6a6876338e6fe 100644 (file)
@@ -26,15 +26,29 @@ extern "C" {
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
 
-      fll_error_file_print(
-        &main->program.error,
-        F_status_set_fine(main->setting.state.status),
-        macro_fss_read_f(fll_fss_extended_read),
-        fll_error_file_flag_fallback_e,
-        fss_read_file_identify(main->setting.range.start, main->setting.files),
-        f_file_operation_process_s,
-        fll_error_file_type_file_e
-      );
+      // Handle knownable errors with more user-friendly messages.
+      switch (F_status_set_fine(main->setting.state.status)) {
+        case F_end_not_eos:
+        case F_end_not_group_eos:
+        case F_end_not_group_stop:
+        case F_end_not_nest_eos:
+        case F_end_not_nest_stop:
+        case F_end_not_stop:
+          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
+
+          break;
+
+        default:
+          fll_error_file_print(
+            &main->program.error,
+            F_status_set_fine(main->setting.state.status),
+            macro_fss_read_f(fll_fss_extended_read),
+            fll_error_file_flag_fallback_e,
+            fss_read_file_identify(main->setting.range.start, main->setting.files),
+            f_file_operation_process_s,
+            fll_error_file_type_file_e
+          );
+      }
 
       return;
     }
index b894701f02c7013d3506fc05e30c1b4907a5aecb..07dd060170b19c85a627bebee2293c3fe834ecc8 100644 (file)
@@ -26,15 +26,29 @@ extern "C" {
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
 
-      fll_error_file_print(
-        &main->program.error,
-        F_status_set_fine(main->setting.state.status),
-        macro_fss_read_f(fll_fss_extended_list_read),
-        fll_error_file_flag_fallback_e,
-        fss_read_file_identify(main->setting.range.start, main->setting.files),
-        f_file_operation_process_s,
-        fll_error_file_type_file_e
-      );
+      // Handle knownable errors with more user-friendly messages.
+      switch (F_status_set_fine(main->setting.state.status)) {
+        case F_end_not_eos:
+        case F_end_not_group_eos:
+        case F_end_not_group_stop:
+        case F_end_not_nest_eos:
+        case F_end_not_nest_stop:
+        case F_end_not_stop:
+          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
+
+          break;
+
+        default:
+          fll_error_file_print(
+            &main->program.error,
+            F_status_set_fine(main->setting.state.status),
+            macro_fss_read_f(fll_fss_extended_list_read),
+            fll_error_file_flag_fallback_e,
+            fss_read_file_identify(main->setting.range.start, main->setting.files),
+            f_file_operation_process_s,
+            fll_error_file_type_file_e
+          );
+      }
 
       return;
     }
index a0b6d1b5948e24e5880ef14ff3196f2cd2e9f52a..44cd97304b43959b4eb5fd56740cd9898e08a6de 100644 (file)
@@ -28,6 +28,24 @@ extern "C" {
   }
 #endif // _di_fss_read_print_error_file_
 
+#ifndef _di_fss_read_print_error_fss_end_early_
+  f_status_t fss_read_print_error_fss_end_early(fl_print_t * const print, const f_string_static_t name) {
+
+    if (!print) return F_status_set_error(F_output_not);
+    if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not;
+
+    f_file_stream_lock(print->to);
+
+    fl_print_format("%[%QFailed to parse the file '%]", print->to, print->context, print->prefix, print->context);
+    fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable);
+    fl_print_format("%[' could not be parsed because the data is not in a supported format or has syntax errors.%]%r", print->to, print->context, print->context, f_string_eol_s);
+
+    f_file_stream_unlock(print->to);
+
+    return F_okay;
+  }
+#endif // _di_fss_read_print_error_fss_end_early_
+
 #ifndef _di_fss_read_print_error_parameter_requires_message_
   f_status_t fss_read_print_error_parameter_requires_message(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name, const f_string_static_t message) {
 
index 4aad0b07ddc9f29440fdc644b956d16da98107fe..f29707cfbed828fffd8641ad9d1bfe0cb3d7fb58 100644 (file)
@@ -71,6 +71,28 @@ extern "C" {
 #endif // _di_fss_read_print_error_file_
 
 /**
+ * Print file related error regarding that the data is not in a correct or valid format.
+ *
+ * @param print
+ *   The output structure to print to.
+ *
+ *   The print.custom is expected to be of type fss_read_main_t.
+ *
+ *   This does not alter print.custom.setting.state.status.
+ * @param name
+ *   The name of the file.
+ *
+ * @return
+ *   F_okay on success.
+ *   F_output_not on success, but no printing is performed.
+ *
+ *   F_output_not (with error bit) if a parameter is NULL.
+ */
+#ifndef _di_fss_read_print_error_fss_end_early_
+  extern f_status_t fss_read_print_error_fss_end_early(fl_print_t * const print, const f_string_static_t name);
+#endif // _di_fss_read_print_error_fss_end_early_
+
+/**
  * Print an error message about the parameter requires something that is explained by the message parameter.
  *
  * @param print