Skip to content

A free open source IT asset/license management system

add a try catch around template validation

Godfrey Mf4e69679ca0a
diff --git a/app/View/Label.php b/app/View/Label.php
index a7c6641a51..e3f0ba7248 100644
--- a/app/View/Label.php
+++ b/app/View/Label.php
@@ -38,7 +38,6 @@ class Label implements View
$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 @@ class Label implements View
->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(),