Skip to content

[3.0] Passes fatalLang() its arguments in the right order - #9343

Merged
jdarwood007 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/fatallang-args
Aug 2, 2026
Merged

[3.0] Passes fatalLang() its arguments in the right order#9343
jdarwood007 merged 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/fatallang-args

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

public static function fatalLang(string $error, string|bool $log = 'general', array $sprintf = [], int $status = 403, string $file = 'Errors'): void

Sources/Actions/Calendar.php puts the HTTP status in the third slot in all 27 of its calls:

ErrorHandler::fatalLang('calendar_off', false, 403);
ErrorHandler::fatalLang('invalid_month', false, 400);
ErrorHandler::fatalLang('event_title_missing', false, 400);

Under strict_types every one of those is a TypeError, so the calendar never delivers a single one of the messages it means to deliver. It reports this instead:

SMF\ErrorHandler::fatalLang(): Argument #3 ($sprintf) must be of type array,
int given, called in /var/www/html/Sources/Actions/Calendar.php on line 116

Which covers the calendar being switched off, an invalid month, year, day or date, a missing event title, a topic that is not yours, a missing topic ID, an out-of-range number of days, and the iCal export being disabled. All of them end in a 500 and the generic "An error has occurred" instead of the written explanation and the right status code.

Sources/Actions/Admin/Themes.php has the same mistake in a different shape: it hands $sprintf a bare string where package_get_error_theme_no_based_on_found wants {0} filled in, so installing a theme that depends on a missing base theme fails with a TypeError rather than naming the theme you need.

The status codes involved were either the default 403 or a plain 400, so nothing is lost by moving them into the parameter they belong in. Sources/Forum.php, Sources/Topic.php and Sources/Actions/HelpAdmin.php already show the intended shape:

ErrorHandler::fatalLang('not_found', false, [], 404);

Testing

Docker environment, PostgreSQL 17, calendar toggled on and off.

before after
?action=calendar, calendar off 500, "Argument #3 ($sprintf) must be of type array" 403, "You cannot access the calendar right now because it is disabled."
?action=calendar;month=5;year=1800 500, TypeError 400, "Invalid year value."
?action=calendar;sa=ical, export off 500, TypeError 403, the export-disabled message
?action=calendar;sa=post without permission 500, TypeError 403
?action=calendar normally 200 200, unchanged

Error log empty across the run. vendor/bin/phpunit — 108 tests, 157 assertions, OK.

Found while checking what the PostgreSQL error reporting in #9341 exposed. Not a query failure, and unrelated to that change.

Issues References (Fixes|Related|Closes)

Related to #9341

fatalLang() takes ($error, $log, $sprintf, $status). Calendar.php puts the
HTTP status where $sprintf goes in all 27 of its calls, and Themes.php hands
that parameter a bare string.

Under strict_types every one of those is a TypeError, so the calendar never
reports a problem it means to report: an invalid month or day, a topic that
is not yours, a missing event title, or the calendar simply being switched
off all end in "Argument #3 ($sprintf) must be of type array" instead of
the message that was written for them. The status codes were the default
403 or plain 400, so nothing is lost by moving them into the slot they
belong in.

Sources/Forum.php, Topic.php and HelpAdmin.php already show the intended
shape: fatalLang('not_found', false, [], 404).

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 5 milestone Aug 2, 2026
@jdarwood007 jdarwood007 added the Localization Language & internationalization label Aug 2, 2026
@jdarwood007
jdarwood007 merged commit bf8d05c into SimpleMachines:release-3.0 Aug 2, 2026
4 checks passed
@albertlast
albertlast deleted the 3.0/fatallang-args branch August 2, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Localization Language & internationalization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants