Skip to content

Commit baaaf6a

Browse files
JohnRDOrazioclaude
andcommitted
Add JSON_THROW_ON_ERROR to json_encode calls for fail-fast behavior
Hardens all json_encode calls in RegionalDataHandler to throw JsonException on encoding failures instead of silently returning false. This ensures any encoding issues surface immediately rather than potentially writing invalid data to calendar and i18n files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e58a426 commit baaaf6a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Handlers/RegionalDataHandler.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private function createDiocesanCalendar(ResponseInterface $response): ResponseIn
361361
);
362362

363363
// Use raw payload for json_encode to preserve schema-compliant structure
364-
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
364+
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
365365
if (
366366
false === file_put_contents(
367367
$diocesanCalendarFile,
@@ -447,7 +447,7 @@ private function createNationalCalendar(ResponseInterface $response): ResponseIn
447447
);
448448

449449
// Use raw payload for json_encode to preserve schema-compliant structure
450-
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
450+
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
451451
if (
452452
false === file_put_contents(
453453
$nationalCalendarFile,
@@ -536,7 +536,7 @@ private function createWiderRegionCalendar(ResponseInterface $response): Respons
536536
);
537537

538538
// Use raw payload for json_encode to preserve schema-compliant structure
539-
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
539+
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
540540
if (
541541
false === file_put_contents(
542542
$widerRegionFile,
@@ -654,7 +654,7 @@ private function updateNationalCalendar(ResponseInterface $response): ResponseIn
654654
}
655655

656656
// Use raw payload for json_encode to preserve schema-compliant structure
657-
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
657+
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
658658
if (
659659
false === file_put_contents(
660660
$calendarFile,
@@ -747,7 +747,7 @@ private function updateWiderRegionCalendar(ResponseInterface $response): Respons
747747
}
748748

749749
// Use raw payload for json_encode to preserve schema-compliant structure
750-
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
750+
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
751751
if (
752752
false === file_put_contents(
753753
$widerRegionFile,
@@ -838,7 +838,7 @@ private function updateDiocesanCalendar(ResponseInterface $response): ResponseIn
838838
}
839839

840840
// Use raw payload for json_encode to preserve schema-compliant structure
841-
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
841+
$calendarData = json_encode($rawPayload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
842842
if (
843843
false === file_put_contents(
844844
$DiocesanCalendarFile,
@@ -1095,7 +1095,7 @@ private function writeI18nFiles(\stdClass $rawPayload, JsonData $i18nFileEnum, a
10951095
if (
10961096
false === file_put_contents(
10971097
$i18nFile,
1098-
json_encode($litCalEventsI18n, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL
1098+
json_encode($litCalEventsI18n, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR) . PHP_EOL
10991099
)
11001100
) {
11011101
throw new ServiceUnavailableException("Failed to write to file {$i18nFile}");
@@ -1155,7 +1155,7 @@ private function updateI18nFiles(
11551155
);
11561156
}
11571157

1158-
$i18nContent = json_encode($i18nData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
1158+
$i18nContent = json_encode($i18nData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
11591159
if (false === file_put_contents($i18nFile, $i18nContent . PHP_EOL)) {
11601160
throw new ServiceUnavailableException(
11611161
"Could not update {$resourceDescription} i18n resource at {$i18nFile}."

0 commit comments

Comments
 (0)