500 error when attempting to access the financial page

Quick follow-up: I was able to get this fixed.

The issue was with the admin finance page at:

/admin/finances

The error in the Laravel log showed PHP memory being exhausted, with Carbon showing in the stack trace.

The problem ended up being in:

app/Support/Dates.php

Specifically, the getMonthsList() function was using addMonth() while building the finance month list. In my case, the first journal date was on the 31st of the month. Since the next month did not have 31 days, the month loop could skip the expected current month and keep running until PHP ran out of memory.

The fix was to start from the first day of the month and use addMonthNoOverflow().

Original:

public static function getMonthsList(Carbon $start_date): array
{
    $months = [];
    $now = date('Y-m');
    $last_month = $start_date;

    do {
        $last_value = $last_month->format('Y-m');
        $months[$last_value] = $last_month->format('Y F');
        $last_month = $last_month->addMonth();
    } while ($last_value !== $now);

    return $months;
}

Updated:

public static function getMonthsList(Carbon $start_date): array
{
    $months = [];

    $last_month = $start_date->copy()->startOfMonth();
    $end_month = Carbon::now()->startOfMonth();

    while ($last_month->lessThanOrEqualTo($end_month)) {
        $last_value = $last_month->format('Y-m');
        $months[$last_value] = $last_month->format('Y F');

        $last_month->addMonthNoOverflow();
    }

    return $months;
}

After saving the change and clearing the application cache, the finance page loaded normally again.

So in my case, it was not a bad finance record. It was the month list loop getting stuck when the first journal date was on the 31st.