sonatype-lift[bot] commented on code in PR #975:
URL: https://github.com/apache/solr/pull/975#discussion_r957767548


##########
solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java:
##########
@@ -215,54 +216,58 @@ public void handleRequest(SolrQueryRequest req, 
SolrQueryResponse rsp) {
         }
       }
     } catch (Exception e) {
-      if (req.getCore() != null) {
-        boolean isTragic = 
req.getCoreContainer().checkTragicException(req.getCore());
-        if (isTragic) {
-          if (e instanceof SolrException) {
-            // Tragic exceptions should always throw a server error
-            assert ((SolrException) e).code() == 500;
-          } else {
-            // wrap it in a solr exception
-            e = new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
e.getMessage(), e);
-          }
-        }
-      }
-      boolean incrementErrors = true;
-      boolean isServerError = true;
-      if (e instanceof SolrException) {
-        SolrException se = (SolrException) e;
-        if (se.code() == SolrException.ErrorCode.CONFLICT.code) {
-          incrementErrors = false;
-        } else if (se.code() >= 400 && se.code() < 500) {
-          isServerError = false;
-        }
-      } else {
-        if (e instanceof SyntaxError) {
-          isServerError = false;
-          e = new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
-        }
-      }
-
+      e = normalizeReceivedException(req, e);
+      processErrorMetricsOnException(e, metrics);
       rsp.setException(e);
+    } finally {
+      long elapsed = timer.stop();
+      metrics.totalTime.inc(elapsed);
+    }
+  }
 
-      if (incrementErrors) {
-        SolrException.log(log, e);
+  public static void processErrorMetricsOnException(Exception e, 
HandlerMetrics metrics) {
+    boolean isClientError = false;
+    if (e instanceof SolrException) {
+      final SolrException se = (SolrException) e;
+      if (se.code() == SolrException.ErrorCode.CONFLICT.code) {
+        return;
+      } else if (se.code() >= 400 && se.code() < 500) {
+        isClientError = true;
+      }
+    }
 
-        metrics.numErrors.mark();
-        if (isServerError) {
-          metrics.numServerErrors.mark();
+    SolrException.log(log, e);
+    metrics.numErrors.mark();
+    if (isClientError) {
+      metrics.numClientErrors.mark();
+    } else {
+      metrics.numServerErrors.mark();
+    }
+  }
+
+  public static Exception normalizeReceivedException(SolrQueryRequest req, 
Exception e) {
+    if (req.getCore() != null) {
+      boolean isTragic = 
req.getCoreContainer().checkTragicException(req.getCore());

Review Comment:
   đŸ’Ŧ 3 similar findings have been found in this PR
   
   ---
   
   *NULL_DEREFERENCE:*  object returned by `req.getCoreContainer()` could be 
null and is dereferenced at line 250.
   
   ---
   
   <details><summary><b>🔎 Expand here to view all instances of this 
finding</b></summary><br/>
   
   <div align="center">
   
   | **File Path** | **Line Number** |
   | ------------- | ------------- |
   | solr/core/src/java/org/apache/solr/cloud/ZkController.java | 
[1285](https://github.com/gerlowskija/solr/blob/112dd72d41e3d472590f8cc29eedae766f81b73d/solr/core/src/java/org/apache/solr/cloud/ZkController.java#L1285)|
   | solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java | 
[115](https://github.com/gerlowskija/solr/blob/112dd72d41e3d472590f8cc29eedae766f81b73d/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java#L115)|
   | solr/core/src/java/org/apache/solr/cloud/ZkController.java | 
[1699](https://github.com/gerlowskija/solr/blob/112dd72d41e3d472590f8cc29eedae766f81b73d/solr/core/src/java/org/apache/solr/cloud/ZkController.java#L1699)|
   <p><a 
href="https://lift.sonatype.com/results/github.com/apache/solr/01GBNHAB9HV5K2ZMGK4T6GD0S0?t=Infer|NULL_DEREFERENCE"
 target="_blank">Visit the Lift Web Console</a> to find more details in your 
report.</p></div></details>
   
   
   
   ---
   
   <details><summary><b>ℹī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=323998399&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=323998399&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=323998399&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=323998399&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=323998399&lift_comment_rating=5)
 ]



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to