From 3ef1ae35d66209d8e32f1807818e49a31dbe44e9 Mon Sep 17 00:00:00 2001 From: Bob Sira Date: Tue, 22 Jul 2025 15:50:06 +0100 Subject: [PATCH 1/2] fix JSON parser to correctly handle numeric values --- LogMonitor/src/LogMonitor/JsonFileParser.cpp | 4 ++-- LogMonitor/src/LogMonitor/LogFileMonitor.cpp | 22 +++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/LogMonitor/src/LogMonitor/JsonFileParser.cpp b/LogMonitor/src/LogMonitor/JsonFileParser.cpp index 54f4cde0..b64ce9a0 100644 --- a/LogMonitor/src/LogMonitor/JsonFileParser.cpp +++ b/LogMonitor/src/LogMonitor/JsonFileParser.cpp @@ -248,9 +248,9 @@ JsonFileParser::ParseNumber() else { // - // End of string. + // End of number. + // Do NOT consume the terminating character. (e.g. comma, bracket, end of array, etc.) // - offset++; AdvanceBufferPointer(offset); m_doubleValue = negativeValue ? -parsedValue : parsedValue; diff --git a/LogMonitor/src/LogMonitor/LogFileMonitor.cpp b/LogMonitor/src/LogMonitor/LogFileMonitor.cpp index fbf1427d..ce58bb60 100644 --- a/LogMonitor/src/LogMonitor/LogFileMonitor.cpp +++ b/LogMonitor/src/LogMonitor/LogFileMonitor.cpp @@ -701,13 +701,21 @@ LogFileMonitor::InitializeDirectoryChangeEventsQueue() nullptr); if (logFile == INVALID_HANDLE_VALUE) { - logWriter.TraceError( - Utility::FormatString( - L"Error in log file monitor. Failed to open file %ws. Error = %d", - fileName.c_str(), - GetLastError() - ).c_str() - ); + // + // Added a conditional check to suppress logging for ERROR_NOT_SUPPORTED (benign error). + // This prevents unnecessary log pollution while still logging other actionable errors. + // https://github.com/microsoft/windows-container-tools/issues/125#issuecomment-3056545183 + // + if (GetLastError() != ERROR_NOT_SUPPORTED) + { + logWriter.TraceError( + Utility::FormatString( + L"Error in log file monitor. Failed to open file %ws. Error = %d", + fileName.c_str(), + GetLastError() + ).c_str() + ); + } // // Ignore failure and continue. In the worst case we will From 40bf2130db6f0b2ced9deb1f6920af2e2f2d5c44 Mon Sep 17 00:00:00 2001 From: Bob Sira Date: Thu, 7 Aug 2025 18:54:40 +0100 Subject: [PATCH 2/2] moving the parser change to a different PR --- LogMonitor/src/LogMonitor/JsonFileParser.cpp | 4 ++-- LogMonitor/src/LogMonitor/LogFileMonitor.cpp | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/LogMonitor/src/LogMonitor/JsonFileParser.cpp b/LogMonitor/src/LogMonitor/JsonFileParser.cpp index b64ce9a0..54f4cde0 100644 --- a/LogMonitor/src/LogMonitor/JsonFileParser.cpp +++ b/LogMonitor/src/LogMonitor/JsonFileParser.cpp @@ -248,9 +248,9 @@ JsonFileParser::ParseNumber() else { // - // End of number. - // Do NOT consume the terminating character. (e.g. comma, bracket, end of array, etc.) + // End of string. // + offset++; AdvanceBufferPointer(offset); m_doubleValue = negativeValue ? -parsedValue : parsedValue; diff --git a/LogMonitor/src/LogMonitor/LogFileMonitor.cpp b/LogMonitor/src/LogMonitor/LogFileMonitor.cpp index ce58bb60..7ef7c8c5 100644 --- a/LogMonitor/src/LogMonitor/LogFileMonitor.cpp +++ b/LogMonitor/src/LogMonitor/LogFileMonitor.cpp @@ -1087,13 +1087,19 @@ LogFileMonitor::LogFileAddEventHandler( if (status != ERROR_SUCCESS) { status = GetLastError(); - logWriter.TraceError( - Utility::FormatString( - L"Error in log file monitor. Failed to query file ID. File: %ws. Error: %d", - fullLongPath.c_str(), - status - ).c_str() - ); + // Added a conditional check to suppress logging for ERROR_NOT_SUPPORTED (benign error). + // This prevents unnecessary log pollution while still logging other actionable errors. + // https://github.com/microsoft/windows-container-tools/issues/125#issuecomment-3056545183 + if (status != ERROR_NOT_SUPPORTED) + { + logWriter.TraceError( + Utility::FormatString( + L"Error in log file monitor. Failed to query file ID for File: %ws. Error: %d", + fullLongPath.c_str(), + status + ).c_str() + ); + } } status = ReadLogFile(logFileInfo);