You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by gw...@apache.org on 2021/12/17 19:53:13 UTC

[kafka] branch trunk updated: MINOR: Correct usage of ConfigException in file and directory config providers

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

gwenshap pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 33853c1  MINOR: Correct usage of ConfigException in file and directory config providers
33853c1 is described below

commit 33853c154ff24ab4e68efa23893646f093c6333f
Author: Chris Egerton <ch...@confluent.io>
AuthorDate: Fri Dec 17 11:51:02 2021 -0800

    MINOR: Correct usage of ConfigException in file and directory config providers
    
    The two-arg variant is intended to take a property name and value, not an exception message and a cause.
    
    As-is, this leads to confusing log messages like:
    
    ```
    org.apache.kafka.common.config.ConfigException: Invalid value java.nio.file.NoSuchFileException: /my/missing/secrets.properties for configuration Could not read properties from file /my/missing/secrets.properties
    ```
    
    Author: Chris Egerton <ch...@confluent.io>
    
    Reviewers: Gwen Shapira
    
    Closes #11555 from C0urante/patch-1
---
 .../kafka/common/config/provider/DirectoryConfigProvider.java  |  6 ++++--
 .../kafka/common/config/provider/FileConfigProvider.java       | 10 ++++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/config/provider/DirectoryConfigProvider.java b/clients/src/main/java/org/apache/kafka/common/config/provider/DirectoryConfigProvider.java
index bcfe674..b8ca511 100644
--- a/clients/src/main/java/org/apache/kafka/common/config/provider/DirectoryConfigProvider.java
+++ b/clients/src/main/java/org/apache/kafka/common/config/provider/DirectoryConfigProvider.java
@@ -89,7 +89,8 @@ public class DirectoryConfigProvider implements ConfigProvider {
                             p -> p.getFileName().toString(),
                             p -> read(p)));
                 } catch (IOException e) {
-                    throw new ConfigException("Could not list directory " + dir, e);
+                    log.error("Could not list directory {}", dir, e);
+                    throw new ConfigException("Could not list directory " + dir);
                 }
             }
         }
@@ -100,7 +101,8 @@ public class DirectoryConfigProvider implements ConfigProvider {
         try {
             return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
         } catch (IOException e) {
-            throw new ConfigException("Could not read file " + path + " for property " + path.getFileName(), e);
+            log.error("Could not read file {} for property {}", path, path.getFileName(), e);
+            throw new ConfigException("Could not read file " + path + " for property " + path.getFileName());
         }
     }
 
diff --git a/clients/src/main/java/org/apache/kafka/common/config/provider/FileConfigProvider.java b/clients/src/main/java/org/apache/kafka/common/config/provider/FileConfigProvider.java
index 3920da0..41f0119 100644
--- a/clients/src/main/java/org/apache/kafka/common/config/provider/FileConfigProvider.java
+++ b/clients/src/main/java/org/apache/kafka/common/config/provider/FileConfigProvider.java
@@ -18,6 +18,8 @@ package org.apache.kafka.common.config.provider;
 
 import org.apache.kafka.common.config.ConfigData;
 import org.apache.kafka.common.config.ConfigException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.io.Reader;
@@ -35,6 +37,8 @@ import java.util.Set;
  */
 public class FileConfigProvider implements ConfigProvider {
 
+    private static final Logger log = LoggerFactory.getLogger(FileConfigProvider.class);
+
     public void configure(Map<String, ?> configs) {
     }
 
@@ -62,7 +66,8 @@ public class FileConfigProvider implements ConfigProvider {
             }
             return new ConfigData(data);
         } catch (IOException e) {
-            throw new ConfigException("Could not read properties from file " + path, e);
+            log.error("Could not read properties from file {}", path, e);
+            throw new ConfigException("Could not read properties from file " + path);
         }
     }
 
@@ -89,7 +94,8 @@ public class FileConfigProvider implements ConfigProvider {
             }
             return new ConfigData(data);
         } catch (IOException e) {
-            throw new ConfigException("Could not read properties from file " + path, e);
+            log.error("Could not read properties from file {}", path, e);
+            throw new ConfigException("Could not read properties from file " + path);
         }
     }