Skip to content

Commit

Permalink
chore: throw exception if node/mjml not found
Browse files Browse the repository at this point in the history
fixes

Signed-off-by: Fred Carlsen <[email protected]>
  • Loading branch information
sjelfull committed May 26, 2024
1 parent 27610cd commit 538180d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/exceptions/MJMLNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* MJML plugin for Craft CMS 3.x
*
* Render Twig emails with MJML, the only framework that makes responsive email easy.
*
* @link https://superbig.co
* @copyright Copyright (c) 2018 Superbig
*/

namespace superbig\mjml\exceptions;

use yii\base\Exception;

/**
* @author Superbig
* @package MJML
* @since 1.0.0
*/
class MJMLException extends RuntimeException

Check failure on line 20 in src/exceptions/MJMLNotFoundException.php

View workflow job for this annotation

GitHub Actions / PHPStan

Class superbig\mjml\exceptions\MJMLException extends unknown class superbig\mjml\exceptions\RuntimeException.
{
public $cliCommand = '';

public function setCliCommand(string $cmd)
{
$this->cliCommand = $cmd;
}

public function getCliCommand()
{
return $this->cliCommand;
}
}
11 changes: 11 additions & 0 deletions src/services/MJMLService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use superbig\mjml\models\MJMLModel;
use yii\base\ErrorException;
use yii\base\Exception;
use yii\base\InvalidConfigException;

/**
* @author Superbig
Expand Down Expand Up @@ -125,6 +126,16 @@ public function parseCli(?string $html = null): ?MJMLModel
$tempPath = Craft::$app->getPath()->getTempPath() . "/mjml/mjml-{$hash}.html";
$tempOutputPath = Craft::$app->getPath()->getTempPath() . "/mjml/mjml-output-{$hash}.html";

// Check if Node.js exists
if (!file_exists($nodePath)) {
throw new InvalidConfigException("Node.js executable not found at path: {$nodePath}");
}

// Check if MJML CLI exists
if (!file_exists($mjmlCliPath)) {
throw new InvalidConfigException("MJML CLI executable not found at path: {$mjmlCliPath}");
}

try {
if (!file_exists($tempOutputPath)) {
FileHelper::writeToFile($tempPath, $html);
Expand Down

0 comments on commit 538180d

Please sign in to comment.