From a9b37a3f8fd99e45feff22779e8d375314cbb925 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 2 Sep 2024 22:59:59 -0500 Subject: [PATCH] Update: Improve error reporting resulting from unsupported file formats. 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 | 4 ++++ level_3/fss_read/c/basic/fss_read.c | 32 +++++++++++++++++++++-------- level_3/fss_read/c/basic_list/fss_read.c | 32 +++++++++++++++++++++-------- level_3/fss_read/c/embedded_list/fss_read.c | 32 +++++++++++++++++++++-------- level_3/fss_read/c/extended/fss_read.c | 32 +++++++++++++++++++++-------- level_3/fss_read/c/extended_list/fss_read.c | 32 +++++++++++++++++++++-------- level_3/fss_read/c/main/print/error.c | 18 ++++++++++++++++ level_3/fss_read/c/main/print/error.h | 22 ++++++++++++++++++++ 8 files changed, 159 insertions(+), 45 deletions(-) diff --git a/level_1/fl_fss/c/fss/embedded_list.h b/level_1/fl_fss/c/fss/embedded_list.h index 58dd6a0..deedba1 100644 --- a/level_1/fl_fss/c/fss/embedded_list.h +++ b/level_1/fl_fss/c/fss/embedded_list.h @@ -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. diff --git a/level_3/fss_read/c/basic/fss_read.c b/level_3/fss_read/c/basic/fss_read.c index 5e52879..46ee251 100644 --- a/level_3/fss_read/c/basic/fss_read.c +++ b/level_3/fss_read/c/basic/fss_read.c @@ -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; } diff --git a/level_3/fss_read/c/basic_list/fss_read.c b/level_3/fss_read/c/basic_list/fss_read.c index 8a710d4..4146b91 100644 --- a/level_3/fss_read/c/basic_list/fss_read.c +++ b/level_3/fss_read/c/basic_list/fss_read.c @@ -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; } diff --git a/level_3/fss_read/c/embedded_list/fss_read.c b/level_3/fss_read/c/embedded_list/fss_read.c index 8d532e6..32da9f2 100644 --- a/level_3/fss_read/c/embedded_list/fss_read.c +++ b/level_3/fss_read/c/embedded_list/fss_read.c @@ -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; } diff --git a/level_3/fss_read/c/extended/fss_read.c b/level_3/fss_read/c/extended/fss_read.c index 89e8136..3313c3a 100644 --- a/level_3/fss_read/c/extended/fss_read.c +++ b/level_3/fss_read/c/extended/fss_read.c @@ -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; } diff --git a/level_3/fss_read/c/extended_list/fss_read.c b/level_3/fss_read/c/extended_list/fss_read.c index b894701..07dd060 100644 --- a/level_3/fss_read/c/extended_list/fss_read.c +++ b/level_3/fss_read/c/extended_list/fss_read.c @@ -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; } diff --git a/level_3/fss_read/c/main/print/error.c b/level_3/fss_read/c/main/print/error.c index a0b6d1b..44cd973 100644 --- a/level_3/fss_read/c/main/print/error.c +++ b/level_3/fss_read/c/main/print/error.c @@ -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) { diff --git a/level_3/fss_read/c/main/print/error.h b/level_3/fss_read/c/main/print/error.h index 4aad0b0..f29707c 100644 --- a/level_3/fss_read/c/main/print/error.h +++ b/level_3/fss_read/c/main/print/error.h @@ -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 -- 1.8.3.1