Skip to content

Conversation

@mrrobot47
Copy link
Member

Overview

This PR implements comprehensive error tracking for backup failures, sending detailed error information (message, type, code) to EasyEngine dashboard API when backups fail. Previously, EasyEngine dashboard only knew that a backup failed but had no context about why it failed.

Error Code Reference for EasyEngine dashboard

Error Code Categories

Category Range Description
Validation Errors 1xxx Invalid input, unsupported configurations
Configuration Errors 2xxx Missing dependencies, config issues
Resource Errors 3xxx Disk space, filesystem, archive creation issues
Network Errors 4xxx Upload/download failures, database connectivity
Fatal Errors 5xxx PHP fatal errors
Process Interruptions 6xxx Process killed, interrupted, or stopped

Complete Error Code List

1xxx: Validation Errors

Code Error Type Message Example
1001 validation_error "Invalid --dash-auth format. Expected: backup-id:backup-verification-token"
1002 validation_error "Backup is not supported for site type: custom"

2xxx: Configuration Errors

Code Error Type Message Example
2001 configuration_error "rclone is not installed"
2002 configuration_error "rclone backend easyengine does not exist"
2003 lock_error "Another backup/restore process is already running for this site"
2010 configuration_error "zip is not installed (required for backup/restore)"
2011 configuration_error "7z is not installed and could not be auto-installed (apt-get not available)"

3xxx: Resource Errors

Code Error Type Message Example
3001 disk_space_error "Insufficient disk space for backup. Required: 2.5 GB, Available: 1.2 GB"
3002 filesystem_error "Failed to create site backup archive"
3002 filesystem_error "Failed to create WordPress content backup archive"
3002 filesystem_error "Failed to create nginx configuration backup archive"
3002 filesystem_error "Failed to create PHP configuration backup archive"
3002 filesystem_error "Failed to compress database backup into archive"

4xxx: Network & Database Errors

Code Error Type Message Example
4001 network_error "Failed to upload backup to remote storage via rclone"
4002 database_error "Database backup failed for database: wp_example_com"

5xxx: Fatal Errors

Code Error Type Message Example
5001 fatal_error "PHP Fatal Error: Call to undefined function in Site_Backup_Restore.php:456"

6xxx: Process Interruptions

Code Error Type Message Example
6000 interrupted "Backup process was interrupted or killed unexpectedly"

…llbacks

- Add error type constants for categorized error reporting (validation, config, filesystem, network, database, disk_space, lock, fatal, interrupted, unknown)
- Add error tracking properties (message, type, code) to capture failure details
- Create capture_error() method to store error information for API callbacks
- Enhance dash_shutdown_handler() to auto-capture PHP fatal errors and process interruptions
- Update send_dash_failure_callback() to include error details in API payload

Error captures added for:
- Invalid --dash-auth format (1001)
- Unsupported site type (1003)
- rclone not installed (2001)
- rclone backend not configured (2002)
- Concurrent backup process (lock file) (2003)
- Insufficient disk space (3001)
- Tool installation failures (2010, 2011)
- rclone upload failures (4001)
- PHP fatal errors (captured from error_get_last)
- Process interruptions (Ctrl+C, SIGTERM, SIGKILL)
…tency

- Fix indentation inconsistencies in backup functions
- Change unsupported site type error code from 1003 to 1002 for consistency
- Use consistent error codes for fatal errors (5001) and interruptions (6000)
- Improve rclone backend error message to show actual backend name
Add error captures for backup operations:
- Site files archive creation failure (3002)
- WordPress content archive creation failure (3002)
- Nginx configuration archive creation failure (3002)
- PHP configuration archive creation failure (3002)
- Database dump failure (4002)
- Database SQL compression failure (3002)
Error code reference:
- 1xxx: Validation errors (1001, 1002)
- 2xxx: Configuration errors (2001, 2002, 2003, 2010, 2011)
- 3xxx: Filesystem/archive errors (3001, 3002)
- 4xxx: Network/database errors (4001, 4002)
- 5xxx: PHP fatal errors (5001)
- 6xxx: Process interruptions (6000)
Copilot AI review requested due to automatic review settings December 22, 2025 05:51
@mrrobot47 mrrobot47 merged commit 7e610e4 into EasyEngine:develop Dec 22, 2025
5 of 9 checks passed
@mrrobot47 mrrobot47 deleted the feat/backup-restore-error-callbacks branch December 22, 2025 05:52
Copy link
Contributor

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 implements comprehensive error tracking for backup failures in EasyEngine, enabling the EasyEngine dashboard to receive detailed error context (message, type, and code) when backups fail. Previously, the dashboard only knew that a backup failed without understanding the root cause.

  • Adds error type constants and tracking properties to categorize failures into validation, configuration, filesystem, network, database, disk space, lock, fatal, and interrupted errors
  • Implements capture_error() method that records the first error encountered and a shutdown handler that automatically detects PHP fatal errors or interrupted processes
  • Updates all backup operations to capture errors before calling EE::error(), ensuring consistent error reporting to the dashboard API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Error tracking for EasyDash failure callbacks
private $dash_error_message = '';
private $dash_error_type = 'unknown';
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The initialization value 'unknown' does not match the constant ERROR_TYPE_UNKNOWN which is defined as 'unknown_error'. This inconsistency means that if no error is captured before the shutdown handler runs, the error_type sent to the dashboard will be 'unknown' instead of 'unknown_error', which doesn't match the documented error types. Consider using self::ERROR_TYPE_UNKNOWN for initialization or changing the value to match the constant.

Suggested change
private $dash_error_type = 'unknown';
private $dash_error_type = self::ERROR_TYPE_UNKNOWN;

Copilot uses AI. Check for mistakes.
if ( strpos( $output->stdout, $rclone_path ) === false ) {
EE::error( 'rclone backend easyengine does not exist. Please create it using `rclone config`' );
$this->capture_error(
sprintf( 'rclone backend "%s" is not configured. Please create it using `rclone config`', $rclone_backend ),
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The error message sent to the dashboard doesn't match the documented message in the PR description. According to the documentation table, error code 2002 should have message "rclone backend easyengine does not exist", but the actual message being sent is "rclone backend "%s" is not configured. Please create it using rclone config". Consider either updating the code to match the documentation or updating the documentation to reflect this more descriptive error message.

Suggested change
sprintf( 'rclone backend "%s" is not configured. Please create it using `rclone config`', $rclone_backend ),
sprintf( 'rclone backend "%s" does not exist. Please create it using `rclone config`', $rclone_backend ),

Copilot uses AI. Check for mistakes.
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.

1 participant