Repository navigation
Conversation
hardDelete collected errors with String.concat, whose result was ignored, so the message was always empty, nothing was thrown and the failure left no trace. Keep the best-effort behaviour and log each failure. Fixes Sonar java:S2201. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
| projectDAO.delete(projectId); | ||
| } catch (Exception e) { | ||
| message.concat(e.getMessage()); | ||
| logger.error("Couldn't delete project {} from the database", projectId, e); |
| } | ||
| if (!message.isEmpty()) { | ||
| throw new InternalErrorException(message); | ||
| logger.error("Couldn't delete project {} from the index", projectId, e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FederatedProjectPersistence.hardDeletecollected failures withmessage.concat(e.getMessage()).String.concatreturns a new string, somessagestayed"", theInternalErrorExceptionbelow it could never be thrown, and a failed database or index delete left no trace at all. Each failure is now logged with its stack trace, and the deadmessage/throwcode is removed.Fixes SonarCloud issues
AaHWUyLo45Pg1SGp66jQandAaHWUyLo45Pg1SGp66jR(java:S2201,FederatedProjectPersistence.java:104and:110).Why it is safe
hardDeleteattempts both stores and never throws. The only difference is twologger.errorcalls.FederatedProjectPersistenceTestcovers both stores being deleted, and the index delete still running (without an exception) when the database delete fails../gradlew :federatedpersistence:test --tests '*FederatedProjectPersistenceTest'passes.Not changed, for a maintainer to decide
The original code evidently meant to throw when either delete failed. Doing that now would turn
DELETE /projects/{id}?hard=trueinto a 500 for a partially created project (missing database or index), which is the caseProjectDeleteServiceallows hard delete for, and would replace the "Could not create project" error in thesavecleanup path. This PR keeps the current best-effort behaviour rather than choose that.Implemented in session Get SonarCloud analysis landing for exec-mms
Review with Devin · Open in Devin Desktop