You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2014/11/03 17:49:59 UTC

git commit: Improve error messages in case of invalid file paths or URIs

Repository: incubator-flink
Updated Branches:
  refs/heads/master f0fd8823e -> 8b39ba9e4


Improve error messages in case of invalid file paths or URIs

This closes #170


Project: http://git-wip-us.apache.org/repos/asf/incubator-flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-flink/commit/8b39ba9e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-flink/tree/8b39ba9e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-flink/diff/8b39ba9e

Branch: refs/heads/master
Commit: 8b39ba9e45145a30c2b95c47d7b03bc3ed2a8a3a
Parents: f0fd882
Author: Stephan Ewen <se...@apache.org>
Authored: Thu Oct 30 20:50:15 2014 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Mon Nov 3 17:10:57 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/flink/core/fs/FileSystem.java   | 13 ++++++++++---
 .../apache/flink/core/fs/local/LocalFileSystem.java |  4 ++--
 .../runtime/fs/hdfs/DistributedFileSystem.java      | 16 +++++++++++++++-
 3 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/8b39ba9e/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java b/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
index ef59996..1b7b91e 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/FileSystem.java
@@ -209,10 +209,17 @@ public abstract class FileSystem {
 				}
 				catch (URISyntaxException e) {
 					// we tried to repair it, but could not. report the scheme error
-					throw new IOException("FileSystem: Scheme is null. file:// or hdfs:// are example schemes. "
-							+ "Failed for " + uri.toString() + ".");
+					throw new IOException("The file URI '" + uri.toString() + "' is not valid. "
+							+ " File URIs need to specify aboslute file paths.");
 				}
 			}
+			
+			if (uri.getScheme().equals("file") && uri.getAuthority() != null && !uri.getAuthority().isEmpty()) {
+				String supposedUri = "file:///" + uri.getAuthority() + uri.getPath();
+				
+				throw new IOException("Found local file path with authority '" + uri.getAuthority() + "' in path '"
+						+ uri.toString() + "'. Hint: Did you forget a slash? (correct path would be '" + supposedUri + "')");
+			}
 
 			final FSKey key = new FSKey(uri.getScheme(), uri.getAuthority());
 
@@ -224,7 +231,7 @@ public abstract class FileSystem {
 			// Try to create a new file system
 			if (!FSDIRECTORY.containsKey(uri.getScheme())) {
 				throw new IOException("No file system found with scheme " + uri.getScheme()
-				+ ". Failed for " + uri.toString() + ".");
+						+ ", referenced in file URI '" + uri.toString() + "'.");
 			}
 
 			Class<? extends FileSystem> fsClass = null;

http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/8b39ba9e/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
index 7c547a2..a33720b 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java
@@ -101,11 +101,11 @@ public class LocalFileSystem extends FileSystem {
 		final File path = pathToFile(f);
 		if (path.exists()) {
 			return new LocalFileStatus(pathToFile(f), this);
-		} else {
+		}
+		else {
 			throw new FileNotFoundException("File " + f + " does not exist or the user running "
 					+ "Flink ('"+System.getProperty("user.name")+"') has insufficient permissions to access it.");
 		}
-
 	}
 
 

http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/8b39ba9e/flink-runtime/src/main/java/org/apache/flink/runtime/fs/hdfs/DistributedFileSystem.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/fs/hdfs/DistributedFileSystem.java b/flink-runtime/src/main/java/org/apache/flink/runtime/fs/hdfs/DistributedFileSystem.java
index d90da6e..d5f370f 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/fs/hdfs/DistributedFileSystem.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/fs/hdfs/DistributedFileSystem.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.URI;
+import java.net.UnknownHostException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -255,6 +256,7 @@ public final class DistributedFileSystem extends FileSystem {
 
 	@Override
 	public void initialize(URI path) throws IOException {
+		
 		// For HDFS we have to have an authority
 		if (path.getAuthority() == null) {
 			
@@ -301,8 +303,20 @@ public final class DistributedFileSystem extends FileSystem {
 			try {
 				this.fs.initialize(path, this.conf);
 			}
+			catch (UnknownHostException e) {
+				String message = "The HDFS namenode host at '" + path.getAuthority()
+						+ "', specified by file path '" + path.toString() + "', cannot be resolved"
+						+ (e.getMessage() != null ? ": " + e.getMessage() : ".");
+				
+				if (path.getPort() == -1) {
+					message += " Hint: Have you forgotten a slash? (correct URI would be 'hdfs:///" + path.getAuthority() + path.getPath() + "' ?)";
+				}
+				
+				throw new IOException(message, e);
+			}
 			catch (Exception e) {
-				throw new IOException("The given file URI (" + path.toString() + ") described the host and port of an HDFS Namenode, but the File System could not be initialized with that address"
+				throw new IOException("The given file URI (" + path.toString() + ") points to the HDFS Namenode at "
+						+ path.getAuthority() + ", but the File System could not be initialized with that address"
 					+ (e.getMessage() != null ? ": " + e.getMessage() : "."), e);
 			}
 		}