Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call of deprecated function print_error() in autologin.php #858

Open
danowar2k opened this issue Jan 8, 2025 · 2 comments
Open

Call of deprecated function print_error() in autologin.php #858

danowar2k opened this issue Jan 8, 2025 · 2 comments
Labels

Comments

@danowar2k
Copy link

What happened?
Moodle's print_error() function is deprecated since Moodle 4.1, see https://tracker.moodle.org/browse/MDL-71062

The code still contains a spot where print_error() is used:

print_error('errorinvalidautologin', 'auth_saml2');

This should be replaced with throwing an exception.

@danowar2k danowar2k changed the title Call of since Moodle 4.1 deprecated function print_error() Call of deprecated function print_error() (since Moodle 4.1) Jan 8, 2025
@anku57
Copy link

anku57 commented Jan 9, 2025

The error you're encountering happens because the print_error() function was deprecated in Moodle 4.1. The recommended approach now is to replace the use of print_error() with throwing an exception, which is more aligned with modern PHP practices and Moodle's exception handling system.

Here's how you can address this issue:

  1. Locate the print_error function call:
    In the file moodle-auth_saml2/autologin.php, line 34, you have the following call:

    print_error('errorinvalidautologin', 'auth_saml2');
  2. Replace print_error() with an exception:
    Instead of using print_error(), you should throw a moodle_exception. This is Moodle's preferred method for error handling now.

    Replace the line with the following code:

    throw new moodle_exception('errorinvalidautologin', 'auth_saml2');

    The moodle_exception class is designed to handle errors more efficiently, and it integrates with Moodle's error handling framework, including displaying the error message appropriately.

Why is this change necessary?

  • Deprecation: print_error() was deprecated as of Moodle 4.1 in favour of exception handling, which allows for better error reporting and debugging.
  • Exception Handling: Throwing an exception is a more modern and consistent way to handle errors in object-oriented programming. Exceptions can be caught, logged, and managed in a way that improves maintainability and readability of the code.

Final Updated Code:

// Line 34 in autologin.php
throw new moodle_exception('errorinvalidautologin', 'auth_saml2');

This will ensure that the code aligns with Moodle's new error handling practices and should resolve the deprecation warning you're seeing.

@danmarsden danmarsden changed the title Call of deprecated function print_error() (since Moodle 4.1) Call of deprecated function print_error() in autologin.php Jan 20, 2025
@danmarsden
Copy link
Member

thanks @danowar2k - if you want to help further, feel free to send through a PR :-)

@danmarsden danmarsden added the bug label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants