ChisomUma opened a new pull request, #10661:
URL: https://github.com/apache/gravitino/pull/10661

   Title: [#10659] fix(core): Correctly handle tag rename conflict in TagManager
      Reference: https://www.conventionalcommits.org/en/v1.0.0/
   
   ### What changes were proposed in this pull request?
   
   This PR improves the error handling in `TagManager.alterTag` when a tag is 
renamed to a name that already exists in the same metalake. 
   
   Specifically:
   - Caught `EntityAlreadyExistsException` during the [alterTag] 
TagManager.java operation.
   - Added logic to extract the intended `newName` from the [TagChange] 
TagChange.java array.
   - Now throws a domain-specific `TagAlreadyExistsException` with a clear 
message, ensuring the server returns an HTTP 409 (Conflict) instead of an HTTP 
500 (Internal Server Error).
   
   ### Why are the changes needed?
   
   Previously, renaming a tag to an existing name caused the server to return a 
generic `RuntimeException`, which surfaced as an HTTP 500 error to the client. 
This is a valid user mistake that should be handled as a conflict (HTTP 409) 
with a descriptive error message.
   
   Fix: #(10659)
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, it changes the error response when a tag rename conflict occurs:
   - **Old behavior**: Returns HTTP 500 (Internal Server Error).
   - **New behavior**: Returns HTTP 409 (Conflict) with the message: `"Tag with 
name <newName> under metalake <metalake> already exists"`.
   
   ### How was this patch tested?
   
   Added a new unit test [testAlterTagRenameToExistingTag] TestTagManager.java 
`core/src/test/java/org/apache/gravitino/tag/TestTagManager.java` that 
specifically covers this scenario:
   1. Creates two tags.
   2. Attempts to rename the first tag to the second's name.
   3. Asserts that `TagAlreadyExistsException` is thrown with the correct 
message.
   4. Verifies that the state of both tags remains unchanged.
   
   Verified the fix by running:
   `./gradlew :core:test --tests "org.apache.gravitino.tag.TestTagManager" 
-PskipITs`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to