diff --git a/src/scount/c/statistics.c b/src/scount/c/statistics.c index 6515f6c..a739115 100644 --- a/src/scount/c/statistics.c +++ b/src/scount/c/statistics.c @@ -21,7 +21,29 @@ #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("An error was encountered for the following file: '%s'", file->path); + const char* const statErr = ( + stats->state.errorMessage + ? stats->state.errorMessage + : "" + ); + const char* const fileErr = ( + result->state.errorMessage + ? 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 + } +} + +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 +63,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; // Show the first file-specific error only + } + } + } } 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..14c9ba9 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 "An error was encountered for the following file:"; + assert_stderr_contains "mixedWithSyntaxError/02_has_syntax_error.c"; } function test_scount_with_valid_directory_input_and_stop_on_error_option() {