Skip to content

Conversation

@bobsira
Copy link
Contributor

@bobsira bobsira commented Jul 22, 2025

This pull request improves error handling in the LogFileMonitor component by suppressing unnecessary error logs for benign ERROR_NOT_SUPPORTED cases. This helps prevent log pollution and ensures only actionable errors are logged.

Error handling improvements:

  • Added a conditional check in LogFileMonitor::InitializeDirectoryChangeEventsQueue() to suppress logging for ERROR_NOT_SUPPORTED, reducing unnecessary log entries for benign errors.
  • Updated LogFileMonitor::LogFileAddEventHandler() to only log errors when the status is not ERROR_NOT_SUPPORTED, further preventing log pollution.

Logging clarity:

  • Ensured that only actionable errors are logged by guarding error trace calls with the new conditional check in both affected methods. [1] [2]Previously, the parser advanced the buffer pointer one character too far after parsing a number, causing it to skip important JSON structural characters (such as commas or closing braces). This led to errors when parsing numbers that were not the last member in an object. The fix ensures the parser leaves the terminating character in place, allowing correct parsing of all numeric values regardless of their position in the

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a JSON parser bug where numeric values caused parsing failures when they weren't the last element in an object. The fix corrects buffer pointer advancement to avoid skipping structural characters after numbers.

  • Removed incorrect buffer pointer advancement after parsing numbers to preserve terminating characters
  • Added error handling improvements to suppress benign ERROR_NOT_SUPPORTED logging
  • Updated code comments to clarify the numeric parsing behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
JsonFileParser.cpp Fixed buffer pointer advancement logic and updated comments for numeric value parsing
LogFileMonitor.cpp Added conditional check to suppress logging of benign ERROR_NOT_SUPPORTED errors

Comment on lines +709 to +718
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()
);
}
Copy link
Contributor

@mloskot mloskot Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bobsira I think similar workaround is needed here

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()
);

I'm testing your LogMonitor.exe build you linked in #214 (comment) and

image

The waitInSeconds: 10 does not seem to help delay the files query in this particular case.

My LogMonitorConfig.json is this

{
  "LogConfig": {
    "sources": [
      {
        "includeSubdirectories": false,
        "filter": "*.log",
        "directory": "C:\\Logs",
        "waitInSeconds": 10,
        "type": "File",
        "includeFileNames": true
      }
    ]
  }
}

The fix for ordering of the waitInSeconds seem to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mloskot please confirm if the issue still exists in this binary -> https://minikubevhdimagebuider.blob.core.windows.net/versions/LogMonitor.exe

It has the change you've suggested. if it's there we can move this fix to a different PR and let this handle the parser fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bobsira Hmm, I've just tested LogMonitor.exe from that URL

Invoke-WebRequest -Uri 'https://minikubevhdimagebuider.blob.core.windows.net/versions/LogMonitor.exe' -OutFile C:/LogMonitor.exe -UseBasicParsing

and this version is reported inside the container - am I using the right custom ad-hoc build of yours?

image

but I can't see any difference

image

Here is my config inside the container

image

and logs location

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, strange that should be the binary with the change. I'll go ahead and split the PR for now. I have a feeling this issue might be coming from another place in the code as well so let's have it addressed in a different PR.

Copy link
Contributor

@mloskot mloskot Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Let's take baby steps. The overall direction seems fine though 😊

@bobsira bobsira changed the title Fix JSON parser to correctly handle numeric values Suppress unnecessary error log for ERROR_NOT_SUPPORTED cases Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants