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

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


The following commit(s) were added to refs/heads/master by this push:
     new b12dbe782d8 [improve][cli] Better error message for pulsar-admin 
schema upload (#20876)
b12dbe782d8 is described below

commit b12dbe782d82d859a68657f0464ba83bd04cb63e
Author: tison <[email protected]>
AuthorDate: Wed Jul 26 12:55:00 2023 +0800

    [improve][cli] Better error message for pulsar-admin schema upload (#20876)
    
    Signed-off-by: tison <[email protected]>
---
 .../java/org/apache/pulsar/admin/cli/CmdSchemas.java     | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java
index 44ac143e350..638e9b1840a 100644
--- 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java
+++ 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java
@@ -23,8 +23,10 @@ import com.beust.jcommander.ParameterException;
 import com.beust.jcommander.Parameters;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.file.Path;
 import java.util.function.Supplier;
 import org.apache.pulsar.admin.cli.utils.SchemaExtractor;
 import org.apache.pulsar.client.admin.PulsarAdmin;
@@ -104,7 +106,19 @@ public class CmdSchemas extends CmdBase {
         @Override
         void run() throws Exception {
             String topic = validateTopicName(params);
-            PostSchemaPayload input = MAPPER.readValue(new 
File(schemaFileName), PostSchemaPayload.class);
+            Path schemaPath = Path.of(schemaFileName);
+            File schemaFile = schemaPath.toFile();
+            if (!schemaFile.exists()) {
+                final StringBuilder sb = new StringBuilder();
+                sb.append("Schema file ").append(schemaPath).append(" is not 
found.");
+                if (!schemaPath.isAbsolute()) {
+                    sb.append(" Relative path ").append(schemaPath)
+                            .append(" is resolved to 
").append(schemaPath.toAbsolutePath())
+                            .append(". Try to use absolute path if the 
relative one resolved wrongly.");
+                }
+                throw new FileNotFoundException(sb.toString());
+            }
+            PostSchemaPayload input = MAPPER.readValue(schemaFile, 
PostSchemaPayload.class);
             getAdmin().schemas().createSchema(topic, input);
         }
     }

Reply via email to