From f4e69679ca0a7e7cd87dd785bc47aeef1e7b51d1 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 8 Jan 2025 12:13:31 -0800 Subject: [PATCH] add a try catch around template validation --- app/View/Label.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/View/Label.php b/app/View/Label.php index a7c6641a519..e3f0ba72480 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -38,7 +38,6 @@ public function render(callable $callback = null) $settings = $this->data->get('settings'); $assets = $this->data->get('assets'); $offset = $this->data->get('offset'); - $template = LabelModel::find($settings->label2_template); // If disabled, pass to legacy view if ((!$settings->label2_enable)) { @@ -49,11 +48,24 @@ public function render(callable $callback = null) ->with('count', $this->data->get('count')); } - if ($template === null) { - throw new \UnexpectedValueException('Template is null.'); + try { + $template = LabelModel::find($settings->label2_template); + + if ($template === null) { + throw new \UnexpectedValueException('Template is null.'); + } + + $template->validate(); + } catch (\UnexpectedValueException $e) { + + \Log::error('Validation failed: ' . $e->getMessage()); + + } catch (\Throwable $e) { + + \Log::error('An unexpected error occurred: ' . $e->getMessage()); + } - $template->validate(); $pdf = new TCPDF( $template->getOrientation(),