From bde805fd5a274c316b680d8f82e608822cdfcc1f Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Mon, 12 Oct 2026 16:07:48 -0700 Subject: [PATCH] fix(import): log the current template error instead of a stale success Signed-off-by: Thomas Vincent --- CHANGELOG.md | 1 + tests/Unit/TemplateImportErrorLoggingTest.php | 35 +++++++++++++++++++ thold_templates.php | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/TemplateImportErrorLoggingTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 07233889..9e2966ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## ChangeLog --- develop --- +* issue: Log each template import error using its own message (#757) * bug: Element-qualify the `.thold-pill` CSS so it outranks the single-class theme rules (e.g. `.deviceUpFull` `width:14%`) that were clipping the pill to a fixed width; status pills now size to their label on the Device Status page and everywhere else * feature: Clicking an already-selected status pill now clears that filter (resets to All) instead of re-applying it, on the Thresholds, Device Status and Threshold Log sub-tabs * bug: Pass a boolean (not the integer `1`) to `api_plugin_register_hook()`'s `$enable` argument so the hook registration stays type-correct under Cacti 1.3's strict `bool $enable` type-hint (the int only coerces while this file lacks `declare(strict_types=1)`) diff --git a/tests/Unit/TemplateImportErrorLoggingTest.php b/tests/Unit/TemplateImportErrorLoggingTest.php new file mode 100644 index 00000000..b4f9d05b --- /dev/null +++ b/tests/Unit/TemplateImportErrorLoggingTest.php @@ -0,0 +1,35 @@ +assertNotEmpty($loop); + $return_data = ['errors' => ['missing field', 'invalid template']]; + $message = 'previous success'; + $debug_data = []; + // Run the production loop body using the existing logging recorder. + foreach ($return_data['errors'] as $error) { + eval($loop[1]); + } + $this->assertSame([ + 'NOTE: Template Import Error!. Message: missing field', + 'NOTE: Template Import Error!. Message: invalid template', + ], CactiStubs::$log); + } +} diff --git a/thold_templates.php b/thold_templates.php index 82980d1d..731bfe51 100644 --- a/thold_templates.php +++ b/thold_templates.php @@ -2718,7 +2718,7 @@ function template_import() { if (isset($return_data['errors'])) { foreach ($return_data['errors'] as $error) { $debug_data[] = '' . __('ERROR:', 'thold') . ' ' . $error; - cacti_log('NOTE: Template Import Error!. Message: ' . $message, false, 'THOLD'); + cacti_log('NOTE: Template Import Error!. Message: ' . $error, false, 'THOLD'); } }