config_preview_deploy-1.0.0-alpha3/src/PatchException.php

src/PatchException.php
<?php

declare(strict_types=1);

namespace Drupal\config_preview_deploy;

/**
 * Exception thrown when patch application fails.
 */
class PatchException extends \Exception {

  /**
   * The patch tool exit code.
   */
  protected int $patchExitCode;

  /**
   * Constructs a PatchException.
   *
   * @param string $message
   *   The exception message.
   * @param int $patchExitCode
   *   The patch tool exit code.
   * @param \Throwable|null $previous
   *   The previous throwable used for exception chaining.
   */
  public function __construct(string $message, int $patchExitCode = 0, ?\Throwable $previous = NULL) {
    parent::__construct($message, 0, $previous);
    $this->patchExitCode = $patchExitCode;
  }

  /**
   * Get the patch tool exit code.
   */
  public function getPatchExitCode(): int {
    return $this->patchExitCode;
  }

  /**
   * Get human-readable error message based on exit code.
   */
  public function getPatchErrorMessage(): string {
    $messages = [
      1 => 'Patch failed - some hunks could not be applied',
      2 => 'Patch malformed or corrupt',
      3 => 'Patch could not be applied due to file conflicts',
      4 => 'Invalid patch options or arguments',
    ];

    return $messages[$this->patchExitCode] ?? 'Unknown patch error';
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc