This is an automated email from the ASF dual-hosted git repository.

mthomsen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/master by this push:
     new 23fa2d3  NIFI-7264 Make jsonPath Expression Logging More Reasonable 
add special handling of PathNotFoundExceptions to log to debug fix spelling 
error wrap debug log in guard per review
23fa2d3 is described below

commit 23fa2d3138c13e418b40be760e33d7d386ddf98e
Author: Otto Fowler <[email protected]>
AuthorDate: Tue Mar 17 11:27:21 2020 -0400

    NIFI-7264 Make jsonPath Expression Logging More Reasonable
    add special handling of PathNotFoundExceptions to log to debug
    fix spelling error
    wrap debug log in guard per review
    
    This closes #4148
    
    Signed-off-by: Mike Thomsen <[email protected]>
---
 .../language/evaluation/functions/JsonPathEvaluator.java       | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git 
a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathEvaluator.java
 
b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathEvaluator.java
index c496285..31958ff 100644
--- 
a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathEvaluator.java
+++ 
b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathEvaluator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.nifi.attribute.expression.language.evaluation.functions;
 
+import com.jayway.jsonpath.PathNotFoundException;
 import org.apache.nifi.attribute.expression.language.EvaluationContext;
 import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
 import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
@@ -46,7 +47,16 @@ public class JsonPathEvaluator extends JsonPathBaseEvaluator 
{
         Object result = null;
         try {
             result = documentContext.read(compiledJsonPath);
+        } catch (PathNotFoundException pnf) {
+            // it is valid for a path not to be found, keys may not be there
+            // do not spam the error log for this, instead we can log debug if 
enabled
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("PathNotFoundException for JsonPath " + 
compiledJsonPath.getPath(), pnf);
+            }
+            return EMPTY_RESULT;
         } catch (Exception e) {
+            // a failure for something *other* than path not found however, 
should at least be
+            // logged.
             LOGGER.error("Exception while reading JsonPath " + 
compiledJsonPath.getPath(), e);
             return EMPTY_RESULT;
         }

Reply via email to