MCD_ERROR: surface error logs in Release builds#67
Conversation
Two coupled fixes that make MCD_ERROR diagnostics actually visible in Release builds: 1. CmuConsoleDebug::GetInstance() now always returns a valid static instance. The previous behaviour (return nullptr unless CSK_LH_DEBUG_CONSOLE was defined) made every g_ConsoleDebug->Write call site a null-pointer member-function call. It "worked" only because the Write body was empty without CONSOLE_DEBUG; any code added there would have crashed in Release. 2. Write() now routes MCD_ERROR to g_ErrorReport.Write (file-based, always compiled) before the existing CONSOLE_DEBUG-gated path. MCD_SEND / MCD_RECEIVE / MCD_NORMAL stay debug-only so production logs don't get flooded. Net effect: any MCD_ERROR call site -- including the safe_cast size mismatch diagnostics added in PR #66 -- now lands in MuError.log even in Release builds.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enables persistent error logging for Release builds by decoupling MCD_ERROR messages from the debug-only console output. By ensuring the console debug instance is always initialized and routing error logs to the existing file-based error reporting system, the changes allow critical diagnostic information to be captured in production environments without introducing unnecessary noise from trace-level logs. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request ensures that CmuConsoleDebug::GetInstance always returns a valid instance to prevent null-pointer dereferences and updates the Write method to always log MCD_ERROR types to the error report regardless of debug flags. A high-severity issue was identified in the new logging logic where the use of a small fixed-size buffer and an unsafe vswprintf call could lead to a buffer overflow; a suggestion was provided to use a larger buffer and a size-limited formatting function to ensure safety and consistency.
| wchar_t szErrorBuffer[256] = L""; | ||
| va_list pArgsForFile; | ||
| va_start(pArgsForFile, pStr); | ||
| vswprintf(szErrorBuffer, pStr, pArgsForFile); | ||
| va_end(pArgsForFile); |
There was a problem hiding this comment.
The buffer szErrorBuffer is limited to 256 characters, which may be insufficient for detailed error messages (e.g., long file paths or complex packet diagnostics). More importantly, the use of vswprintf with only 3 arguments is non-standard and unsafe as it lacks a buffer size limit, risking a buffer overflow if the formatted string exceeds the buffer capacity. Note that CErrorReport::Write in ErrorReport.cpp correctly uses the 4-argument version of vswprintf with a 1024-character limit. To ensure safety and consistency, the buffer size should be increased and the size-limited version of the formatting function should be used.
| wchar_t szErrorBuffer[256] = L""; | |
| va_list pArgsForFile; | |
| va_start(pArgsForFile, pStr); | |
| vswprintf(szErrorBuffer, pStr, pArgsForFile); | |
| va_end(pArgsForFile); | |
| wchar_t szErrorBuffer[1024] = L""; | |
| va_list pArgsForFile; | |
| va_start(pArgsForFile, pStr); | |
| vswprintf(szErrorBuffer, 1024, pStr, pArgsForFile); | |
| va_end(pArgsForFile); |
Summary
Makes
g_ConsoleDebug->Write(MCD_ERROR, ...)actually produce output in stock Release builds. Companion to PR #66 — without this change, the safe_cast size-mismatch diagnostics added there compile but never reach the user, because the entireWritebody is gated by#ifdef CONSOLE_DEBUG(not defined in any production build).Changes
src/source/Core/Utilities/Log/muConsoleDebug.cpp:CmuConsoleDebug::GetInstance()now always returns a valid static instance. Previously it returnednullptrunlessCSK_LH_DEBUG_CONSOLEwas defined, which made everyg_ConsoleDebug->Write(...)call site a null-pointer member-function call. It only "worked" because theWritebody was empty whenCONSOLE_DEBUGwas undefined; any non-empty code there would have crashed.Write()now routesMCD_ERRORtog_ErrorReport.Write(file-based, always compiled, opensMuError.logon startup) before the existingCONSOLE_DEBUG-gated console path.MCD_SEND / MCD_RECEIVE / MCD_NORMALstay debug-only so production logs aren't flooded with per-packet trace messages.Effect
Any existing or future
g_ConsoleDebug->Write(MCD_ERROR, ...)call -- including the safe_cast diagnostics from PR #66 -- now lands inMuError.login Release builds. Example after the join-map struct guard would trip:MuError.logis rotated by the existingCErrorReport::CutHeadlogic, so this won't grow unbounded.Test plan
MuError.logis created in working dir (already exists today).MuError.log.MuError.log(only ERROR survives Release).Scope notes
CONSOLE_DEBUG-enabled builds: the console output still happens after the file write._EDITOR(ImGui console) path is unchanged — still gated byCONSOLE_DEBUGtogether with the rest of the console output.