This guide covers the comprehensive error handling system introduced in v0.3.0.
Simple RSync Daemon v0.3.0 includes a robust error handling system with:
- Error Categories: Organized error types by domain
- Error Codes: Numeric codes for programmatic handling
- Error Context: Rich contextual information
- Error Recovery: Suggestions for resolving errors
- Structured Error Reporting: JSON and text formats
Errors are organized into the following categories:
| Category | Code Range | Description |
|---|---|---|
| CONFIGURATION | 1000-1999 | Configuration file and validation errors |
| AUTHENTICATION | 2000-2999 | User authentication failures |
| AUTHORIZATION | 3000-3999 | Access control and permission errors |
| NETWORK | 4000-4999 | Network connection and socket errors |
| FILE_SYSTEM | 5000-5999 | File and directory operation errors |
| PROTOCOL | 6000-6999 | RSync protocol parsing errors |
| MODULE | 7000-7999 | Module-specific errors |
| INTERNAL | 8000-8999 | Internal daemon errors |
| EXTERNAL | 9000-9999 | External dependency errors |
| Code | Name | Description |
|---|---|---|
| 1001 | CONFIG_FILE_NOT_FOUND |
Configuration file does not exist |
| 1002 | CONFIG_INVALID_FORMAT |
Configuration file has invalid syntax |
| 1003 | CONFIG_VALIDATION_FAILED |
Configuration validation failed |
| 1004 | CONFIG_RELOAD_FAILED |
Configuration reload failed |
| Code | Name | Description |
|---|---|---|
| 2001 | AUTH_FAILED |
Authentication failed |
| 2002 | AUTH_USER_NOT_FOUND |
User does not exist |
| 2003 | AUTH_PASSWORD_INVALID |
Invalid password |
| 2004 | AUTH_ACCOUNT_LOCKED |
Account is locked |
| 2005 | AUTH_PASSWORD_EXPIRED |
Password has expired |
| 2006 | AUTH_SESSION_EXPIRED |
Session has expired |
| Code | Name | Description |
|---|---|---|
| 3001 | AUTHZ_ACCESS_DENIED |
Access denied |
| 3002 | AUTHZ_INSUFFICIENT_PERMISSIONS |
Insufficient permissions |
| 3003 | AUTHZ_IP_DENIED |
IP address denied |
| Code | Name | Description |
|---|---|---|
| 4001 | NETWORK_CONNECTION_FAILED |
Connection failed |
| 4002 | NETWORK_BIND_FAILED |
Failed to bind to address/port |
| 4003 | NETWORK_LISTEN_FAILED |
Failed to listen on socket |
| 4004 | NETWORK_ACCEPT_FAILED |
Failed to accept connection |
| 4005 | NETWORK_TIMEOUT |
Network operation timed out |
| Code | Name | Description |
|---|---|---|
| 5001 | FS_FILE_NOT_FOUND |
File does not exist |
| 5002 | FS_PERMISSION_DENIED |
Permission denied |
| 5003 | FS_DISK_FULL |
Disk is full |
| 5004 | FS_PATH_TRAVERSAL |
Path traversal attempt detected |
| 5005 | FS_INVALID_PATH |
Invalid file path |
| Code | Name | Description |
|---|---|---|
| 6001 | PROTOCOL_INVALID_MESSAGE |
Invalid protocol message |
| 6002 | PROTOCOL_UNSUPPORTED_VERSION |
Unsupported protocol version |
| 6003 | PROTOCOL_PARSE_ERROR |
Protocol parsing error |
| Code | Name | Description |
|---|---|---|
| 7001 | MODULE_NOT_FOUND |
Module does not exist |
| 7002 | MODULE_INVALID_CONFIG |
Invalid module configuration |
| 7003 | MODULE_OPERATION_FAILED |
Module operation failed |
| Code | Name | Description |
|---|---|---|
| 8001 | INTERNAL_ERROR |
Internal error |
| 8002 | INTERNAL_MEMORY_ERROR |
Memory allocation error |
| 8003 | INTERNAL_THREAD_ERROR |
Thread operation error |
| Code | Name | Description |
|---|---|---|
| 9001 | EXTERNAL_DEPENDENCY_ERROR |
External dependency error |
| 9002 | EXTERNAL_SSL_ERROR |
SSL/TLS error |
#include "simple-rsyncd/core/error.hpp"
try {
// Operation that may fail
daemon.start();
} catch (const RSyncError& e) {
// Handle error
std::cerr << "Error: " << e.toString() << std::endl;
std::cerr << "Code: " << static_cast<int>(e.getCode()) << std::endl;
std::cerr << "Category: " << e.getCategory() << std::endl;
std::cerr << "Recovery: " << e.getRecoverySuggestion() << std::endl;
}#include "simple-rsyncd/core/error.hpp"
// Simple error
throw RSyncError(
ErrorCode::AUTH_FAILED,
"Authentication failed",
ErrorCategory::AUTHENTICATION
);
// Error with context
ErrorContext ctx;
ctx.setComponent("AuthenticationManager")
.setOperation("authenticate")
.setUser("admin")
.setClientAddress("192.168.1.100");
throw RSyncError(
ErrorCode::AUTH_PASSWORD_INVALID,
"Invalid password",
ctx.build(),
ErrorCategory::AUTHENTICATION
);The ErrorContext class provides a fluent interface for building error context:
ErrorContext ctx;
ctx.setComponent("Module")
.setOperation("transferFile")
.setPath("/var/data/file.txt")
.setUser("admin")
.setClientAddress("192.168.1.100")
.addField("file_size", "1024")
.addField("transfer_rate", "512");
std::string context = ctx.build();
// Result: "component=Module, operation=transferFile, path=/var/data/file.txt, ..."Some errors are recoverable and can be retried:
RSyncError error(ErrorCode::NETWORK_TIMEOUT, "Connection timed out");
if (error.isRecoverable()) {
// Retry operation
retryOperation();
} else {
// Handle non-recoverable error
handleError(error);
}Recoverable Errors:
NETWORK_TIMEOUTNETWORK_CONNECTION_FAILEDAUTH_SESSION_EXPIREDCONFIG_RELOAD_FAILED
[CONFIGURATION] [CONFIG_FILE_NOT_FOUND] Configuration file not found (Context: component=Configuration, operation=loadFromFile, path=/etc/simple-rsyncd/rsyncd.conf)
{
"timestamp": "2024-12-14 10:30:45",
"code": 1001,
"code_string": "CONFIG_FILE_NOT_FOUND",
"category": "CONFIGURATION",
"message": "Configuration file not found",
"context": "component=Configuration, operation=loadFromFile, path=/etc/simple-rsyncd/rsyncd.conf",
"fields": {
"component": "Configuration",
"operation": "loadFromFile",
"path": "/etc/simple-rsyncd/rsyncd.conf"
}
}Errors are automatically logged with full context:
try {
// Operation
} catch (const RSyncError& e) {
logger->error(e.toJSON());
// Or
logger->error(e.toString());
}- Always include context: Use
ErrorContextto provide detailed information - Use appropriate error codes: Choose the most specific error code
- Provide recovery suggestions: Help users resolve errors
- Log errors appropriately: Use structured logging for errors
- Handle recoverable errors: Implement retry logic for recoverable errors
Configuration errors are automatically caught and reported:
# Configuration validation will show detailed errors
simple-rsyncd test --config /etc/simple-rsyncd/rsyncd.conf
# Example output:
# Error [CONFIGURATION] [CONFIG_VALIDATION_FAILED]:
# - Module 'backup': path '/var/backup' does not exist
# - SSL certificate file '/etc/ssl/certs/server.crt' not foundWhen troubleshooting, use error codes and categories to identify issues:
- Check error category: Identifies the component with the problem
- Check error code: Provides specific information about the failure
- Review error context: Shows what operation was being performed
- Follow recovery suggestions: Provides actionable steps to resolve
For more information, see the Configuration Guide and Troubleshooting Guide.