Error Manager
Overview
The Error Manager provides comprehensive error handling and debugging support for FreeWorld OS. It implements Windows-compatible error codes, GetLastError/SetLastError functionality, and OutputDebugString with logd integration.
Features
- 200+ Error Codes: Complete Windows-compatible error code set
- GetLastError/SetLastError: Per-thread error tracking
- OutputDebugString: Debug output with logd integration
- Error Messages: Human-readable error messages
- Error Formatting: Formatted error messages with context
- Debug Output Management: Filtering and retrieval of debug output
Error Code Management
Manage error codes per thread:
setLastError(errorCode, threadId)- Set last error for threadgetLastError(threadId)- Get last error for threadclearLastError(threadId)- Clear last errorgetErrorMessage(errorCode)- Get error message for codeformatError(errorCode, ...args)- Format error message with placeholders
Debug Output
OutputDebugString equivalent functionality:
outputDebugString(message, category)- Output debug messagegetDebugOutput(filter)- Get debug output with optional filteringclearDebugOutput()- Clear all debug output
Debug output is automatically integrated with logd for persistent logging.
Error Codes
The Error Manager supports 200+ Windows-compatible error codes, including:
- ERROR_SUCCESS: Operation completed successfully
- ERROR_FILE_NOT_FOUND: File not found
- ERROR_PATH_NOT_FOUND: Path not found
- ERROR_ACCESS_DENIED: Access denied
- ERROR_INVALID_HANDLE: Invalid handle
- ERROR_INVALID_PARAMETER: Invalid parameter
- ERROR_NOT_ENOUGH_MEMORY: Not enough memory
- ERROR_ALREADY_EXISTS: File already exists
- ERROR_SHARING_VIOLATION: File sharing violation
- And 190+ more error codes
Usage Example
const ErrorManager = require('./system/error');
const errorMgr = new ErrorManager();
// Set error
errorMgr.setLastError(ErrorManager.ERROR_CODES.ERROR_FILE_NOT_FOUND);
// Get error
const errorCode = errorMgr.getLastError();
const message = errorMgr.getErrorMessage(errorCode);
console.log(message); // "The system cannot find the file specified."
// Output debug string
errorMgr.outputDebugString('Application started', 'INFO');
errorMgr.outputDebugString('File operation failed', 'ERROR');
// Get debug output
const debugLog = errorMgr.getDebugOutput({ category: 'ERROR' });
Integration
The Error Manager integrates with:
- logd: Automatic logging of debug output
- All System Services: Error reporting throughout the system
- Object Manager: Error codes for file operations
- Security Manager: Access denied errors