eric-maynard commented on code in PR #1348:
URL: https://github.com/apache/polaris/pull/1348#discussion_r2036256675


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/dao/entity/BaseResult.java:
##########
@@ -57,14 +70,90 @@ public String getExtraInformation() {
     return extraInformation;
   }
 
-  public boolean isSuccess() {
+  public final boolean isSuccess() {
     return this.returnStatusCode == ReturnStatus.SUCCESS.getCode();
   }
 
-  public boolean alreadyExists() {
+  public final boolean alreadyExists() {
     return this.returnStatusCode == 
ReturnStatus.ENTITY_ALREADY_EXISTS.getCode();
   }
 
+  /**
+   * If this result is not a successful one, this builds an exception from the 
failed result which
+   * the exception mapper can use to provide the caller some useful 
information about the failure.
+   * The message relies on `extraInformation`. If {@link
+   * 
org.apache.polaris.core.config.FeatureConfiguration#DETAILED_PERSISTENCE_EXCEPTIONS}
 is false,
+   * this should return an empty option.
+   */
+  @SuppressWarnings("FormatStringAnnotation")
+  public Optional<RuntimeException> getException(CallContext callContext) {
+    if (!callContext
+        .getPolarisCallContext()
+        .getConfigurationStore()
+        .getConfiguration(
+            callContext.getPolarisCallContext(),
+            FeatureConfiguration.DETAILED_PERSISTENCE_EXCEPTIONS)) {
+      return Optional.empty();
+    }
+
+    String message = this.extraInformation;
+    if (this.extraInformation == null) {
+      // TODO this should ideally never be hit but it's hit often.

Review Comment:
   If we merge this, we should file an issue(s) tracking the many callsites 
where a non-successful result is built with a `null` message. This might be a 
good starter task.



-- 
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