From e9f53b84ebd81811ae3dec8e69f93886707e4f3b Mon Sep 17 00:00:00 2001 From: kilo52 Date: Fri, 30 Jan 2026 19:22:01 +0100 Subject: [PATCH 1/3] Improved error message to give more details. Added the reportFileError() function to log an additional error message about the source file that produced an error. This gives more information to the user when the input is a directory, as only showing an error for the given directory does not make it clear which source file produced the error specifically. Signed-off-by: kilo52 --- src/scount/c/statistics.c | 32 ++++++++++++++++++- .../tests/functionality/sh/test_scount.sh | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/scount/c/statistics.c b/src/scount/c/statistics.c index 6515f6c..1013431 100644 --- a/src/scount/c/statistics.c +++ b/src/scount/c/statistics.c @@ -21,7 +21,28 @@ #include "reckon/reckon.h" #include "scount.h" -static void reportError(const char* path, RcnCountStatistics* stats) { +static void reportFileError( + const RcnCountStatistics* stats, + const RcnSourceFile* file, + const RcnCountResultGroup* result +) { + logE("The following file encountered an error: '%s'", file->path); + const char* const statErr = ( + stats->state.errorMessage + ? stats->state.errorMessage + : "" + ); + const char* const fileErr = ( + result->state.errorMessage + ? result->state.errorMessage + : "" + ); + if (strcmp(fileErr, "") != 0 && strcmp(statErr, fileErr) != 0) { + logE("%s (%#04x)", fileErr, result->state.errorCode); // LCOV_EXCL_LINE + } +} + +static void reportError(const char* path, const RcnCountStatistics* stats) { if (stats->state.errorCode == RCN_ERR_INVALID_INPUT) { logE("Invalid input path: '%s'", path); } else { @@ -41,6 +62,15 @@ static void reportError(const char* path, RcnCountStatistics* stats) { ); // LCOV_EXCL_STOP } + if (stats->count.size > 1) { + for (size_t i = 0; i < stats->count.size; ++i) { + const RcnCountResultGroup* const result = &stats->count.results[i]; + if (result->state.errorCode != RCN_ERR_NONE) { + reportFileError(stats, &stats->count.files[i], result); + break; + } + } + } } static void reportInputVerbose(const char* path, RcnCountStatistics* stats) { diff --git a/src/scount/tests/functionality/sh/test_scount.sh b/src/scount/tests/functionality/sh/test_scount.sh index c1e7b98..4109efa 100644 --- a/src/scount/tests/functionality/sh/test_scount.sh +++ b/src/scount/tests/functionality/sh/test_scount.sh @@ -154,6 +154,8 @@ function test_scount_with_stop_on_error_option() { assert_stdout_is_empty; assert_stderr_contains "An error has occurred"; assert_stderr_contains "Syntax error detected in source code"; + assert_stderr_contains "The following file encountered an error:"; + assert_stderr_contains "mixedWithSyntaxError/02_has_syntax_error.c"; } function test_scount_with_valid_directory_input_and_stop_on_error_option() { From 98ab77e92c8e7bef60bca9a02b9fdae78f3bf5e9 Mon Sep 17 00:00:00 2001 From: kilo52 Date: Sun, 1 Feb 2026 14:01:22 +0100 Subject: [PATCH 2/3] Added source comments. Signed-off-by: kilo52 --- src/scount/c/statistics.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scount/c/statistics.c b/src/scount/c/statistics.c index 1013431..95f63bf 100644 --- a/src/scount/c/statistics.c +++ b/src/scount/c/statistics.c @@ -37,6 +37,7 @@ static void reportFileError( ? result->state.errorMessage : "" ); + // Report only if it differs from the overall stats error message if (strcmp(fileErr, "") != 0 && strcmp(statErr, fileErr) != 0) { logE("%s (%#04x)", fileErr, result->state.errorCode); // LCOV_EXCL_LINE } @@ -67,7 +68,7 @@ static void reportError(const char* path, const RcnCountStatistics* stats) { const RcnCountResultGroup* const result = &stats->count.results[i]; if (result->state.errorCode != RCN_ERR_NONE) { reportFileError(stats, &stats->count.files[i], result); - break; + break; // Show the first file-specific error only } } } From ac6959aec7f82b684214ceffa168510f9172943e Mon Sep 17 00:00:00 2001 From: kilo52 Date: Sun, 1 Feb 2026 14:05:12 +0100 Subject: [PATCH 3/3] Changed error message. Signed-off-by: kilo52 --- src/scount/c/statistics.c | 2 +- src/scount/tests/functionality/sh/test_scount.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scount/c/statistics.c b/src/scount/c/statistics.c index 95f63bf..a739115 100644 --- a/src/scount/c/statistics.c +++ b/src/scount/c/statistics.c @@ -26,7 +26,7 @@ static void reportFileError( const RcnSourceFile* file, const RcnCountResultGroup* result ) { - logE("The following file encountered an error: '%s'", file->path); + logE("An error was encountered for the following file: '%s'", file->path); const char* const statErr = ( stats->state.errorMessage ? stats->state.errorMessage diff --git a/src/scount/tests/functionality/sh/test_scount.sh b/src/scount/tests/functionality/sh/test_scount.sh index 4109efa..14c9ba9 100644 --- a/src/scount/tests/functionality/sh/test_scount.sh +++ b/src/scount/tests/functionality/sh/test_scount.sh @@ -154,7 +154,7 @@ function test_scount_with_stop_on_error_option() { assert_stdout_is_empty; assert_stderr_contains "An error has occurred"; assert_stderr_contains "Syntax error detected in source code"; - assert_stderr_contains "The following file encountered an error:"; + assert_stderr_contains "An error was encountered for the following file:"; assert_stderr_contains "mixedWithSyntaxError/02_has_syntax_error.c"; }