src/precore/util/Exceptions.php
public static function getRootCause(Exception $exception) : Exception
    {
        $result = null;
        while ($exception !== null) {
            $result = $exception;
            $exception = $exception->getPrevious();
        }
        return $result;
    }
public static function getRootCause(Exception $exception) : Exception
    {
        $result = null;
        while ($exception !== null) {
            $result = $exception;
            $exception = $exception->getPrevious();
        }
        return $result;
    }
Returns the innermost cause of $exception.

@param Exception $exception
@return Exception