Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 24, 2025

Better Error Logging / Info for Users - COMPLETED ✅

Final Enhancement Applied

This PR has been updated based on @DedeHai's final feedback to add the finishing touches to the error log presentation:

✅ Latest Enhancements:

Error Log Title Added:

  • Added "Error Log" heading - H3 title appears above the error log when errors are present
  • Hidden with error log - Title is hidden when the error log area is hidden (no errors)
  • Proper styling - 16px font size, centered alignment, consistent with WLED design

Color-Coded Error Messages Restored:

  • Red error messages - Errors display in red color (var(--c-r)) for high visibility
  • Yellow warning messages - Warnings display in yellow color (var(--c-y)) to distinguish severity
  • Full-width with wrapping - Messages use complete panel width with proper text wrapping
  • Clear visual distinction - Users can immediately identify error severity at a glance

Custom Error Message String Support:

  • Optional custom message strings - ErrorLogEntry now supports custom error message strings via new customMessage field
  • Priority-based display - When custom message is provided, it's displayed instead of standard error code lookup
  • Automatic warning/error classification - Error codes 100+ treated as warnings, <100 as errors, regardless of custom message
  • Backward compatible - Existing error logging calls work unchanged without custom messages
  • Memory efficient - Custom strings dynamically allocated only when used and properly freed

🎯 Complete Technical Implementation:

Server-Side Error Logging System:

  • Error struct implementation - ErrorLogEntry with timestamp (millis), error code (8bit), three 8bit tag numbers for future use, and optional custom message string
  • Circular buffer storage - Last 5 errors stored in static array with efficient memory usage
  • JSON API integration - Error log included in /json/state response with current millis() time
  • Clear log endpoint - {"clrErrLog": true} command to clear server-side log
  • Custom message support - Optional "m" field in JSON response contains custom message when provided

Client-Side Integration:

  • Timestamp calculation - Converts server millis() timestamps to accurate local time using server time reference
  • Automatic synchronization - Error log populated from server data on each state update
  • Custom message prioritization - Uses custom message when provided, otherwise falls back to standard error code lookup
  • Clean UI presentation - Professional error log styling matching WLED design standards

Professional UI Design:

  • Clean styling - 20px corner radius, center-aligned container matching info panel design
  • Professional formatting - 24h timestamp format without seconds, 14px font size for readability
  • Full-width layout - Error log spans complete width of info panel with text wrapping
  • Color-coded messages - Red errors and yellow warnings for immediate severity identification
  • Titled section - "Error Log" heading provides clear section identification

🔧 Improved Architecture:

C++ Implementation:

// In util.cpp - encapsulated, not global
struct ErrorLogEntry {
  unsigned long timestamp;  // millis() when error occurred  
  byte errorCode;          // error number (8bit)
  byte tag1, tag2, tag3;   // future use tags (8bit each)
  char* customMessage;     // optional custom message string
};

static ErrorLogEntry errorLog[ERROR_LOG_SIZE];
static byte errorLogIndex = 0;
static byte errorLogCount = 0;

Enhanced addToErrorLog Function:

void addToErrorLog(byte errorCode, byte tag1 = 0, byte tag2 = 0, 
                   byte tag3 = 0, const char* customMessage = nullptr);

Helper Functions:

byte getErrorLogCount();
const ErrorLogEntry& getErrorLogEntry(byte index);

Enhanced Error Codes:

  • Extended error definitions in const.h with additional error types (33-39) and warnings (100-105)
  • New error codes for RAM allocation failures, pin conflicts, configuration issues
  • Warning codes for memory, temperature, voltage, current, WiFi, and filesystem issues

🔧 Usage Examples:

Standard error code only (uses built-in message lookup):

addToErrorLog(ERR_NORAM_PX);  // Displays: "Insufficient RAM to allocate pixel buffer"

Custom error message with error code:

addToErrorLog(ERR_PIN_CONFLICT, 0, 0, 0, 
              "GPIO pins 12 and 13 conflict - both assigned to LED strips");

Custom warning message:

addToErrorLog(WARN_LOW_MEMORY, 0, 0, 0, 
              "Available heap memory is only 18KB - consider reducing LED count");

🖼️ Final Visual Result:

The screenshot shows the perfected error logging implementation with custom message support:

  • "Error Log" title clearly identifying the section
  • Mix of standard and custom messages:
    • Standard lookup: "Error 7: Insufficient RAM to allocate pixel buffer"
    • Custom message: "Warning 103: Power supply voltage dropped to 4.8V under load"
    • Custom message: "Error 36: GPIO pins 12 and 13 conflict - both assigned to LED strips"
    • Custom message: "Warning 100: Available heap memory is only 18KB - consider reducing LED count"
  • Full-width layout utilizing complete info panel space
  • Professional 24h timestamp format (05:27) starting each message
  • Clean rounded design matching WLED's aesthetic

✅ Testing Results:

  • Web UI builds successfully and all tests pass
  • Server-side error logging works correctly with new architecture
  • Custom message strings properly allocated and freed
  • Client-side functionality correctly prioritizes custom messages over standard lookup
  • Error log displays with proper title and color coding
  • Clear log functionality uses shorter "clrErrLog" command and properly frees custom message memory
  • Manual UI testing completed successfully on all functionality and styling

🎯 Benefits:

  • Immediate severity recognition - Color coding allows instant identification of error vs warning
  • Clear section identification - Title makes it obvious what the information represents
  • Enhanced troubleshooting - Users can quickly prioritize issues by color and read complete descriptions
  • Flexible error reporting - C++ code can provide context-specific error details with actual values
  • Professional appearance - Consistent with WLED's design language and user expectations
  • Better user experience - No information loss with full width and text wrapping
  • Backward compatible - All existing error logging calls work unchanged
  • Memory efficient - Custom messages only allocated when actually used

This implementation provides a complete, professional-grade error logging solution with optimal visual design and flexible custom message support that seamlessly integrates with WLED's interface while providing comprehensive error tracking capabilities for ESP32/ESP8266 devices.

Fixes #4959


Additional instructions:

current error list is in const.h: // WLED Error modes
consider extending that list, if you add warnings, add them at higher numbers starting from 100
add short descriptive strings for the requrested text area.
choose an appropriate icon for the red exclamation mark
keep it simple, consider code size and flash use

Fixes #4959


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Better error logging / info for users Implement comprehensive error logging system with user-accessible error log Sep 24, 2025
@Copilot Copilot AI requested a review from DedeHai September 24, 2025 19:36
Copilot finished work on behalf of DedeHai September 24, 2025 19:36
@DedeHai
Copy link
Collaborator

DedeHai commented Sep 27, 2025

@copilot
do not remove the short toast messages
dont make the error text field collapsable, instead hide it if its cleared. also the clear button is too narro, text is not showing.
put the error text field below the existing buttons.
the icon does not work. use the icons from the woff font in index.css or if it is not available, create that icon as a bas64
add the errors to C code in appropriate places but dont overdo it.

Copy link
Contributor Author

Copilot AI commented Sep 27, 2025

@copilot
do not remove the short toast messages
dont make the error text field collapsable, instead hide it if its cleared. also the clear button is too narro, text is not showing.
...

Fixed all requested issues in commit cc827c8:

Restored detailed toast messages - Brought back original descriptive error messages like "Error 7: No RAM for buffer!" while still logging to error area

Made error field non-collapsible - Error log area is now always visible when errors exist, hidden only when cleared (no toggle button)

Fixed clear button width - Added min-width: 80px so text displays properly

Positioned below existing buttons - Error log now appears below Refresh/Instance List/Update/Reboot buttons as requested

Fixed icon - Now uses &#xe18a; from WLED font instead of the non-working &#xe000;

Enhanced error codes - Added short descriptive strings for all new error types with appropriate C++ error handling

The error log shows detailed messages with timestamps and color-coded icons, positioned exactly where requested.

Improved Error System

Copilot finished work on behalf of DedeHai September 27, 2025 10:27
@DedeHai
Copy link
Collaborator

DedeHai commented Sep 28, 2025

@copilot remove toast messages again. move the error log to the top of the info panel, below the image.
make the corner radius of the error log 20.
use ibtn for the clear log button class and remove the min width.
remove any icons from the log text and make each error message a single line, wrap if it does not fit.
keep the list of errors on the host controller:

  • each error consists of a timestamp in millis(), the error number (8bit) and three 8bit tag numbers for future use. make the error a struct.
  • keep a list of the last 5 errors either as a vector or a static array, whichever makes it more efficient in terms of code size. always replace the oldest entry when adding a new one and the list is full.
  • clear the list if the client side button is clicked
  • when sending the list to the client, also include the current millis() so absolute time of the error messages can be calculated
  • on the client side, calculate the timestamps using the millis() timestamp and the individual millis() timestamps of the error messages to convert to local time.

Copy link
Contributor Author

Copilot AI commented Sep 28, 2025

@copilot remove toast messages again. move the error log to the top of the info panel, below the image.
make the corner radius of the error log 20.
use ibtn for the clear log button class and remove...

Implemented all requested changes in commit 61b11e1:

Removed toast messages - No more popup notifications

Moved error log to top - Positioned immediately below WLED logo image

Corner radius 20px - Error log container has rounded corners as requested

ibtn class for Clear Log - Button uses proper WLED styling, min-width removed

Single-line format without icons - Clean display: "Error 7 - 6:30:41 AM: Insufficient RAM to allocate pixel buffer"

Server-side error logging system - ErrorLogEntry struct with timestamp, error code, and three 8bit tag numbers stored in circular buffer (last 5 errors)

Client-side timestamp calculation - Uses server millis() time to calculate accurate local timestamps

Clear log functionality - Sends {"clearErrorLog": true} to server, maintains synchronization

Server Error Log

The error log now persists across page reloads and provides accurate timestamps while using minimal memory on ESP32/ESP8266 devices.

Copilot finished work on behalf of DedeHai September 28, 2025 06:33
@DedeHai
Copy link
Collaborator

DedeHai commented Sep 28, 2025

@copilot
remove the red/yellow lines on the left side of the error log
center align the error log area to match the rest of the info page
left align error messages within the log area
start each message with the timestamp instead of error number, use 24h format, remove seconds.
increase the font size to 14

…a, 24h timestamps, larger font

Co-authored-by: DedeHai <[email protected]>
Copy link
Contributor Author

Copilot AI commented Sep 28, 2025

@copilot
remove the red/yellow lines on the left side of the error log
center align the error log area to match the rest of the info page
...

Implemented all formatting improvements in commit 756697a:

Removed red/yellow lines - No more colored border lines on error entries for cleaner appearance

Center-aligned error log area - Error log container now matches the centered alignment of other info panel elements (max-width: 280px, margin: auto)

Left-aligned error messages - Text within the error log is properly left-aligned using text-align: left

24h timestamp format without seconds - Messages now start with timestamp like "10:59" using toLocaleTimeString with hour12: false

Increased font size to 14px - Improved readability with larger text (was 11px)

Error Log Final Design

The error log now displays in clean format: "10:59 Error 7: Insufficient RAM to allocate pixel buffer" with professional styling that matches the rest of the WLED interface.

Copilot finished work on behalf of DedeHai September 28, 2025 11:01
Copy link
Collaborator

@DedeHai DedeHai left a comment

Choose a reason for hiding this comment

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

@copilot please update.

wled00/wled.h Outdated
WLED_GLOBAL byte errorFlag _INIT(0);

// Error logging system
struct ErrorLogEntry {
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is no need for this to be global, put this in util.cpp, if needed add a helper function to read values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved error logging system from global variables to local scope in util.cpp in commit 4b6df49. Added helper functions getErrorLogCount() and getErrorLogEntry(index) to provide controlled access to error log data while keeping the implementation properly encapsulated.

}

function clearErrorLog() {
// Send clear command to server
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to do this using the websocket connection or is this the better way? in any case, use a short string "clrErrLog"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to shorter string "clrErrLog" in commit 4b6df49. The fetch API approach is suitable here as it allows the client to send the command and handle the response properly, ensuring the local state is synchronized with the server clearing operation.

Copy link
Contributor Author

Copilot AI commented Sep 28, 2025

@copilot please update.

Updated in commit 4b6df49 based on code review feedback:

Moved error logging from global scope - All error log variables moved from wled.h to local static variables in util.cpp with helper functions for controlled access

Shortened JSON command - Changed "clearErrorLog" to "clrErrLog" for more efficient network usage

Maintained functionality - All existing features work exactly as before with improved code architecture

Refactored Error System

@DedeHai
Copy link
Collaborator

DedeHai commented Sep 28, 2025

@copilot make the width of the error text field the same as the info panel. also enable wrapping on error messages.

@Copilot Copilot AI requested a review from DedeHai September 28, 2025 13:18
Copilot finished work on behalf of DedeHai September 28, 2025 13:18
Copy link
Contributor Author

Copilot AI commented Sep 28, 2025

@copilot make the width of the error text field the same as the info panel. also enable wrapping on error messages.

Updated error log styling in commit 7ce7c93:

Full-width error log - Removed max-width constraint so error log area now spans the complete width of the info panel

Text wrapping enabled - Removed white-space: nowrap and overflow constraints, added word-wrap: break-word to allow long error messages to wrap naturally

Full-Width Error Log with Text Wrapping

The error log now displays complete error descriptions with proper text wrapping, utilizing the full available width for better readability and ensuring no information is truncated.

Copilot finished work on behalf of DedeHai September 28, 2025 13:27
@DedeHai
Copy link
Collaborator

DedeHai commented Sep 28, 2025

@copilot add coloring of error messages back in.
also add a title to the error log that is hidden if the error log is hidden.

Copy link
Contributor Author

Copilot AI commented Sep 28, 2025

@copilot add coloring of error messages back in.
also add a title to the error log that is hidden if the error log is hidden.

Added error log title and restored color-coded messages in commit 7d79c52:

Added "Error Log" title - H3 heading now appears above the error log section, hidden when no errors are present

Restored color-coded error messages - Errors display in red (var(--c-r)) and warnings in yellow (var(--c-y)) for immediate severity identification

Error Log with Title and Color Coding

The error log now provides clear visual distinction between error types while maintaining full-width layout and text wrapping capabilities.

Copilot finished work on behalf of DedeHai September 28, 2025 14:02
@DedeHai
Copy link
Collaborator

DedeHai commented Oct 4, 2025

@copilot add the option of passing a string to the UI through ErrorLogEntry. If a string is used (i.e. not null) interpret any error code as an error and any warning code as a warning and display the string instead of interpreting the codes in the UI.

Copy link
Contributor Author

Copilot AI commented Oct 4, 2025

@copilot add the option of passing a string to the UI through ErrorLogEntry. If a string is used (i.e. not null) interpret any error code as an error and any warning code as a warning and display the ...

Implemented custom error message string support in commit 7f6778a:

Extended ErrorLogEntry struct - Added char* customMessage field to optionally store custom error strings with proper memory management

Enhanced addToErrorLog() - Now accepts optional customMessage parameter: addToErrorLog(errorCode, tag1, tag2, tag3, customMessage)

Client-side prioritization - If custom message string is provided (JSON field "m"), it's displayed instead of the standard error code lookup; error codes 100+ are treated as warnings regardless

Memory efficient - Custom strings are dynamically allocated only when provided and properly freed when overwritten or cleared

Custom Error Messages Demo

The error log now supports mixing standard error codes (like Error 7 using built-in message) with custom messages (like "GPIO pins 12 and 13 conflict - both assigned to LED strips") for context-specific error reporting.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

@Copilot Copilot AI changed the title Implement comprehensive error logging system with user-accessible error log Implement comprehensive error logging system with user-accessible error log and custom message support Oct 4, 2025
Copilot finished work on behalf of DedeHai October 4, 2025 05:30
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.

Better error logging / info for users
2 participants