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

Throw exceptions on SQL errors #18151

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cedric-anne
Copy link
Member

@cedric-anne cedric-anne commented Oct 29, 2024

Checklist before requesting a review

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

Since we did not have a centralized error catching in the past, we were not able to throw exceptions when a SQL error occurred. They were just logged and were not stopping the code execution, and this could have the effect of triggering hard-to-debug errors in subsequently executed code.

Now we have a centralized error catching system, we can throw exceptions when a SQL error is triggered. It would result in displaying the error page. For instance, if I force a SQL querry error in the impact analysis tab:
image

@cedric-anne cedric-anne self-assigned this Oct 29, 2024
@cedric-anne cedric-anne added this to the 11.0.0 milestone Oct 31, 2024
@@ -122,7 +122,7 @@ The present file will list all changes made to the project; according to the
- Usage of `DBmysql::query()`, `DBmysql::queryOrDie()` method are prohibited to ensure that legacy unsafe DB are no more executed.
Building and executing raw queries using `DBmysql::request()`, `DBmysqlIterator::buildQuery()` and `DBmysqlIterator::execute()` methods is also prohibited.
To execute DB queries, either `DBmysql::request()` can be used to craft query using the GLPI query builder,
either `DBmysql::doQuery()`/`DBmysql::doQueryOrDie()` can be used for safe queries to execute DB query using a self-crafted a SQL string.
either `DBmysql::doQuery()` can be used for safe queries to execute DB query using a self-crafted a SQL string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
either `DBmysql::doQuery()` can be used for safe queries to execute DB query using a self-crafted a SQL string.
`DBmysql::doQuery()` can be used for safe queries to execute DB query using a self-crafted a SQL string.

@cedric-anne
Copy link
Member Author

E2E tests are failing due to the SQL error reported in #18175.

Copy link
Contributor

@AdrienClairembault AdrienClairembault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes, should Toolbox::logSqlError() and the associated sql-errors.log file be depreciated/removed ?

With the new exception, SQL errors end up directly in the php-errors-log file.
I don't see a use case for manually calling Toolbox::logSqlError().

@cedric-anne
Copy link
Member Author

With these changes, should Toolbox::logSqlError() and the associated sql-errors.log file be depreciated/removed ?

With the new exception, SQL errors end up directly in the php-errors-log file. I don't see a use case for manually calling Toolbox::logSqlError().

sql-errors.log still contains SQL warnings and SQL debug info. We could change it, but it is out of the scope of the current PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants